Forum Moderators: phranque
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!
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.
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)
My first guess would be to try adding
Options +FollowSymLinks
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