Forum Moderators: phranque

Message Too Old, No Replies

htaccess question

         

vero

9:29 pm on May 16, 2008 (gmt 0)

10+ Year Member



I own the .org and the .com version of a domain

I would like my htaccess file to do two things:
1- redirect the .com url to the .org url (so that the url would change in the address bar to .org, even if someone types in .com)
2 - I would also like any non-www. urls to change to the www.

Is the following the correct way to do BOTH:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.org
RewriteRule ^.*$ http://www.example.org%{REQUEST_URI} [L]

or

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

Or... something else entirely. I've seen these addressed separately, but with different code each time. Thanks!

g1smd

10:36 pm on May 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The latter will work fine.

Your first example is not a redirect, as it does not have the required [R=301] in the code.

If the site does not use parameters in the URLs, I would, at the same time, suppress them in the same redirect.

Additionally, I would add redirects to fix trailing dot and/or port number after domain name.

vero

11:56 pm on May 16, 2008 (gmt 0)

10+ Year Member



Sorry - I'm still having a problem. I put this (with my url of course)

RewriteCond %{HTTP_HOST} !^www\.example\.org
RewriteRule (.*) http://www.example.org/$1 [R=301,L]

at the top of my htaccess file, folowed on the next lines by some 301 redirects that I already had.

I was hoping it would send everything to the www.org url. But when I type in the url with .com, or without the www, the address bar remains the same. I thought the address bar should change, as it does with the other 301 redirects.

I also tried adding

RewriteEngine On

at the top. But then instead of my site, I got an Apache test page (it's on a hosted server)

jdMorgan

2:47 am on May 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you get a test page, or an error page?

My first guess would be to try adding


Options +FollowSymLinks

before "RewriteEngine on"

As documented, either FollowSymLinks or SymLinksIfOwnerMatch must be enabled if you want to execute mod_rewrite directives.

If it still doesn't work, have a look at your server error log file.

Jim