Forum Moderators: phranque

Message Too Old, No Replies

301 Redirect Redirects Main Site Too

         

jonrichd

11:50 am on Nov 25, 2002 (gmt 0)

10+ Year Member



My site has just gotten the .com domain in addition to the existing .net domain we were using previously. I want to make the .com domain the main domain, and the .net domain point to it.

I tried using the mod rewrite rule posted here:

[webmasterworld.com...]

The result was that while the old .net domain now gives the proper 301 redirect, the new .com one does as well.

The rewrite rule I used was:

RewriteEngine on
RewriteCond %{HTTP_HOST]!^www\.mysite\.com$
RewriteRule (.*) [mysite.com...] [R=permanent,L]

Any help would be appreciated. I have learned a lot from this site.

jdMorgan

4:22 pm on Nov 25, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



johnrichd,


RewriteEngine on
RewriteCond %{HTTP_HOST]!^www\.mysite\.com$
RewriteRule (.*) [mysite.com...] [R=permanent,L]

Try this:


Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mysite\.com
RewriteCond %{HTTP_HOST} !^123\.45\.67\.89
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=permanent,L]

The two most-likely causes of trouble are the missing spaces before the "!" characters, and the end-anchor on the HTTP_HOST pattern. Also include your IP address so you can get to your site in case of a DNS failure.

If you install the rewrite in httpd.conf rather than .htaccess, you'll need to modify the RewriteRule to handle the leading slash:


Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mysite\.com
RewriteCond %{HTTP_HOST} !^123\.45\.67\.89
RewriteRule ^(.*)$ http://www.mysite.com$1 [R=permanent,L]

HTH,
Jim

jonrichd

4:53 pm on Nov 25, 2002 (gmt 0)

10+ Year Member



Thanks, jdmorgan, that did the trick. It looks like the first $ was misplaced when I copied it from the other thread.