Forum Moderators: phranque

Message Too Old, No Replies

Backwards Subdomain redirecting

Newbie question...

         

elvissinatra

6:06 pm on Mar 22, 2004 (gmt 0)

10+ Year Member



Sorry if this has been covered previously; I searched but couldn't find anything.

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!

jdMorgan

9:36 pm on Mar 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



elvissinatra,

Welcome to WebmasterWorld [webmasterworld.com]!

Well, here's the RewriteCond you'll need to get this working:


RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com

Now add a RewriteRule to rewrite all requests for files in your "/subdomain" subdirectory over to the true subdomain.

Introduction to mod_rewrite [webmasterworld.com]

Jim

elvissinatra

11:01 pm on Mar 23, 2004 (gmt 0)

10+ Year Member



Awesome! Thanks so much. So I added this code to the end of my htaccess file, and it's doing exactly what I want it to do:

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.

jdMorgan

1:05 am on Mar 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



elvissinatra,

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]

Ref: [httpd.apache.org...] ... See [flags]

Jim