RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
I have another question on this topic.
How would I go about redirecting the .index.html file of a directory to just the directory name itself. For example:
www yoursite com/about-us/index.html would only show as www yoursite com/about-us/
When I try to change htaccess to do a redirect it gives me the error "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."
I am using the code: "Redirect 301 /about-us/index.html hxxp://www yoursite com/about-us/"
No, actually this is one of the recommended uses of a 301. Even google says you should do it, as well as set up the prefered url in webmaster tools.I dont think you actually need a 301 for this, couldn't use just use masking.
@OP - that just doesn't look right. It looks like your trying to use an alias directive. For a mod_alias directive you have to use the status 'permanent' not '301'. Also I'm not sure if you should use the filename in this instance. If that's the case then it should be more like...
I am using the code: "Redirect 301 /about-us/index.html hxxp://www yoursite com/about-us/"
Redirect /about-us http://www.yoursite.com/about-us
Redirect permanent /about-us http://www.yoursite.com/about-us