how do i redirect foo.bar.com to www.bar.com/okay/foo

Discuss practical ways rearrange URLs using mod_rewrite.

how do i redirect foo.bar.com to www.bar.com/okay/foo

Postby verbatim » Sat Jun 18, 2005 8:45 pm

i am trying to configure a rewrite rule that will redirect foo.bar.com to www.bar.com/okay/foo
i have attempted to alter the script below with no luck


############################
rewriteEngine On
# Rewrite <subdomain>.example.com/<path> to example.com/<subdomain>/<path>
#
# Skip rewrite if no hostname or if subdomain is www
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\. [NC]
# Extract (required) subdomain (%1), and first path element (%3), discard port number if present (%2)
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.example\.com(:80)?<>/([^/]*) [NC]
# Rewrite only when subdomain not equal to first path element (prevents mod_rewrite recursion)
RewriteCond %1<>%3!^(.*)<>\1$ [NC]
# Rewrite to /subdomain/path
RewriteRule ^(.*) /%1/$1 [L]

can any one help me please

thanks
verbatim
 
Posts: 3
Joined: Sat Jun 18, 2005 8:42 pm

Postby verbatim » Sun Jun 19, 2005 8:46 am

found the answer in another post: viewtopic.php?t=889

Code: Select all
RewriteCond %{HTTP_HOST} !^(www\.)?(www|mail|images)\.domain\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.domain\.com
# ok rewrite now
RewriteRule ^(.*) http://www.domain.com/%2/$1 [P,L]


thanks

this forum is great
verbatim
 
Posts: 3
Joined: Sat Jun 18, 2005 8:42 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 96 guests

cron