Forum Moderators: phranque
I need to redirect anyone who goes to [mydomain.com...] OR [mydomain.com...] to [subdomain.mydomain.com...]
I'm terrible with regular expressions. No matter how many articles I read about it, it just never sinks in!
Please help! Thanks!
Welcome to WebmasterWorld [webmasterworld.com]!
Well, here's the RewriteCond you'll need to get this working:
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com
Introduction to mod_rewrite [webmasterworld.com]
Jim
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com
RewriteRule subdomain/ http://subdomain.mydomain.com/
Woo hoo! It works, but just out of curiosity, is that the best way to have the rule? I saw something about R and L parameters, but I'm not 100% what they do, so I didn't want to add them.
Basically, always use [L] unless you want to further rewrite the URL that the rule has just processed.
If you want the client (such as a search engine) to drop the old URL and always request the new URL in the future, then use [R=301]. If the URL change is temporary (and there is no official definition of precisely what 'temporary' means), then use [R=302] or just [R]. You can combine them either way, such as [R=301,L] or [L,R].
In this case, I'd suggest:
RewriteRule [b]^su[/b]bdomain/ http://subdomain.mydomain.com/ [b][R=310,L][/b]
Jim