I'm darn nearly pulling my hair out trying to figure this out tonight. I'm hoping someone can help me out.
I have 3 TLD's for a site, similar to the following:
- www.domain.com
- www.domain.org
- www.domain.net
They are all located in the same directory.
I would like to set up 301 redirects so that all pages of the .org and .net point to their respective pages at the .com location.
For example, domain.net/topic/page as well as www.domain.net/topic/page should permanently redirect to www.domain.com/topic/page.
Currently, I am using the code below which only redirects the .net and .org home pages to the .com home page.
RewriteCond %{HTTP_HOST} !^(www.)?domain.com$ [NC]
RewriteRule .?$ http://www.domain.com%{REQUEST_URI} [R=301,L]
Thank you for your time,
Casey
This one is based on your example with minor modification:
NC
,R=301
andL
are pretty obvious. TheNE
is for no-escape and it prevents query string variables from being escaped twice. The^(.*)
does not need a/
in most cases.Note: 301 permanent redirect responses will be cached by the browser so clear your browser cache every now and then while testing. Otherwise you may not see the result of changes you make.