Forum Moderators: phranque

Message Too Old, No Replies

rewriting subdomains

         

tmenusan

9:09 pm on Mar 13, 2006 (gmt 0)

10+ Year Member



Hi,
I have the following code to redirect
http://foo.domain.com to
http://www.domain.com/app.php?sub=foo
I have problem with redirecting with the WWW in the url
EX
http://www.foo.domain.com to
http://www.domain.com/app.php?sub=foo

Any help would be appreciated
Thanks
Sam
------------------------------------------

Options +FollowSymlinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^[^\.w{3}]+\.domain.com$
RewriteRule ^(.*) %{HTTP_HOST}$1 [C]
RewriteRule ^([^\.w{3}]+)\.domain\.com(.*) http://www.domain.com/app.php?sub=$1 [R=301,L]

[edited by: jdMorgan at 1:11 am (utc) on Mar. 16, 2006]
[edit reason] De-linked. [/edit]

jdMorgan

12:53 am on Mar 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



tmenusan,

Welcome to WebmasterWorld!

I'd suggest a simpler approach:


RewriteCond %{HTTP_HOST} !www\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule .* http://www.example.com/app.php?sub=%1 [R=301,L]

or in order to avoid 'exposing' your subdirectories:

RewriteCond %{HTTP_HOST} !www\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule .* /app.php?sub=%1 [L]

In both case, %1 back-references the subdomain name captured in the second RewriteCond.

Jim

tmenusan

2:40 pm on Mar 15, 2006 (gmt 0)

10+ Year Member



Thanks Jim,
I have tried both.
However they were not doing the redirect.

Thanks again for your help