Forward users who use WWW in URL
<p>Every user on my website get its own URL for usernames like <code>username.example.com</code>. I know that sometimes people are typing <code>www</code> in front the URL. When users do that, they will get redirected by the system to the frontpage. Is there a way to (1) detect the use of <code>www</code>, (2) the username and (3) forward the user to <code>username.example.com</code>, NOT <code>www.username.example.com</code> with PHP?</p>

<p>This is not a DNS-releated question.</p>

<pre><code>RewriteEngine On
Options +Followsymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_FILENAME} !^.*/images/.*$
RewriteCond %{REQUEST_FILENAME} !^.*/uploads/.*$
RewriteCond %{HTTP_HOST}&lt;&gt;%{REQUEST_URI} ^([^.]+)\.bloggify\.no(:80)?&lt;&gt;/([^/]*) [NC]
RewriteCond %1&lt;&gt;%3 !^(.*)&lt;&gt;\1$ [NC]
RewriteRule ^(.*)$ - [E=BLOGUSER:%1]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^$ /index.php?w=%1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^page([0-9]+)/([^/]+)?$ /index.php?w=%1&amp;page=$1$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^profiles/([^/]+)/([^/]+)?$ /profile.php?u=$1$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^profiles/?$ /profile.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^albums/([^/]+)/([^/]+)?$ /album.php?u=$1$2 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^archive/(.*)/(.*)/([^/]+)?$ /archive.php?w=%1&amp;y=$1&amp;m=$2$3 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^archive\.php/(.*)/(.*)/([^/]+)?$ /archive.php?w=%1&amp;y=$1&amp;m=$2$3 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^archive/(.*)/([^/]+)?$ /archive.php?w=%1&amp;y=$1$2 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^archive\.php/(.*)/([^/]+)?$ /archive.php?w=%1&amp;y=$1$2 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^archive/([^/]+)?$ /archive.php?w=%1$1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^archive\.php/([^/]+)?$ /archive.php?w=%1$1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^friends/([^/]+)?$ /friends.php?w=%1$1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^friends\.php/([^/]+)?$ /friends.php?w=%1$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/friends/page([0-9]+)/([^/]+)?$ /friends.php?w=$1&amp;page=$2$3 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^([0-9]+)/([^/]+).html$ /entry.php?w=%1&amp;e_id=$1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^([0-9]+)/([^/]+)?$ /entry.php?w=%1&amp;e_id=$1$2 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^&amp;([^/]+)?$ /index.php?w=%1&amp;$1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^([^/]+)/([^/]+)?$ /index.php?w=%1&amp;category=$1$2 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^([^/]+)/page([0-9]+)/([^/]+)?$ /index.php?w=%1&amp;category=$1&amp;page=$2$3 [L]
</code></pre>
