Forum Moderators: phranque
I found some examples on how to do the opposite but I couldn't reverse-engineer them to what I want.
Is mod_rewrite what I need, and if so can someone clue me in?
TIA,
Frank.
PS
Arrgh!
:)
# Redirect www.mysite.com to mysite.com:
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$
RewriteRule ^(.*)$ [mysite.com...] [R=permanent,L]
# Redirect anything except mysite.com to mysite.com:
RewriteCond %{HTTP_HOST} !^mysite\.com$
RewriteRule ^(.*)$ [mysite.com...] [R=permanent,L]
<added>The second version is useful if you have multiple TLDs, like .com and .org, pointed to the same site and you want to redirect them all to the same URL, as well as removing the "www."</added>
More details here [httpd.apache.org].
Jim
Make sure you've got symbolic links enabled, and that the rewrite engine is enabled. And before even checking that, make sure that the rewrite module is installed and that you have priveleges to use it!
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^mysite\.com$
RewriteRule ^(.*)$ [mysite.com...] [R=permanent,L]
This code has worked for years on my site. If the above hints don't help you, then you may stickymail me your actual code if you think there's some subtle typo in your version - it does have to be letter-perfect.
Jim
Tell them you need "AllowOverride +Options" in the directory level above the directory your .htaccess file is in. If your .htaccess is in your site's top-level directory, then they will need to add this option in the server config for you. Actually, you might want to ask for "AllowOverride All" at first, and see if they'll go for it... :) (See the Apache Core docs for AllowOverride.)
Jim