i want my subdomain with www.subdomain.example.com redirec

Discuss practical ways rearrange URLs using mod_rewrite.

i want my subdomain with www.subdomain.example.com redirec

Postby hmarei » Fri Jun 27, 2008 8:22 pm

hi :o ,
I Have a Weblog Service! I had a Domain & With this domain my customer Opening their Blog. For Example : http://blogname.example.com
but when they type http://www.blogname.example.com don't open their blog.
i want my subdomain with www.subdomain.example.com redirect to subdomain.examlpe.com or ignore www !

how to set htaccess ?

Thanks,

---------------- MY htaccess Code ---------------------

Code: Select all
RewriteEngine On
Options +Followsymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\. [NC]
RewriteCond %{REQUEST_FILENAME}!^.*/images/.*$
RewriteCond %{REQUEST_FILENAME}!^.*/uploads/.*$
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.example\.com(:80)?<>/([^/]*) [NC]
RewriteCond %1<>%3!^(.*)<>\1$ [NC]
RewriteRule ^(.*)$ - [E=BLOGUSER:%1]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^$ /index.php?w=%1 [L]
RewriteRule ^page([0-9]+)/([^/]+)?$ /index.php?w=%1&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&y=$1&m=$2$3 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^archive/(.*)/([^/]+)?$ /archive.php?w=%1$1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^archive/([^/]+)?$ /archive.php?w=%1$1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^friends/([^/]+)?$ /friends.php?w=%1$1 [L]
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^([^/]+)/friends/page([0-9]+)/([^/]+)?$ /friends.php?w=$1&page=$2$3 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^([0-9]+)/([^/]+)?$ /entry.php?w=%1&e_id=$1$2 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ([^/]+)^$ /index.php?w=%1$1 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^([^/]+)/([^/]+)?$ /index.php?w=%1&category=$1$2 [L]
RewriteCond %{ENV:BLOGUSER} ^(.+)$
RewriteRule ^([^/]+)/page([0-9]+)/([^/]+)?$ /index.php?w=%1&category=$1&page=$2$3 [L]
hmarei
 
Posts: 5
Joined: Fri Jun 29, 2007 1:51 am

Postby richardk » Sat Jun 28, 2008 4:51 pm

Try adding
Code: Select all
RewriteCond %{HTTP_HOST} ^www\.(.+\.example\.com)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

after
Code: Select all
RewriteBase /


You can probably shorten
Code: Select all
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\. [NC]
RewriteCond %{REQUEST_FILENAME}!^.*/images/.*$
RewriteCond %{REQUEST_FILENAME}!^.*/uploads/.*$
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.example\.com(:80)?<>/([^/]*) [NC]
RewriteCond %1<>%3!^(.*)<>\1$ [NC]
RewriteRule ^(.*)$ - [E=BLOGUSER:%1]

to
Code: Select all
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^([^\.]+)\.example\.com(:80)?/\1(/.*)?$ [NC]
RewriteRule !^(images|uploads)(/.*)?$ - [E=BLOGUSER:%1]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 37 guests

cron