I'm darn nearly tugging my hair out attempting to figure this out tonight. I am wishing someone can assist me.

I've 3 TLD's for any site, like the following:

  • world wide web.domain.com
  • world wide web.domain.org
  • world wide web.domain.internet

They all are situated within the same directory.

I must setup 301 redirects to ensure that all pages from the .org and .internet indicate their particular pages in the .com location.

For instance, domain.internet/subject/page in addition to world wide web.domain.internet/subject/page should permanently redirect to world wide web.domain.com/subject/page.

Presently, I'm while using code below which only redirects the .internet and .org home pages towards the .com webpage.

RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteRule .?$ http://www.domain.com%{REQUEST_URI} [R=301,L]

Appreciate your time and effort,

Casey

RewriteCond %{HTTP_HOST}   domain\.(org|net) [NC]
RewriteRule ^/(.*)         http://www.domain.com/$1 [L,R=301]

You will find a number of other method to write the Cond, this is the way Used to do mine - an optimistic compare. Yours is an adverse compare, however it has got the drawback when someone does not send a number header it'll redirect forever, around the plus you don't have to list all of the domain names to redirect. You can also give a rule to redirect .com without world wide web if you would like.

For that Rule the secret may be the () within the expression - this captures that area of the url to be used later using the $1

That one is dependant on your example with minor modification:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [R=301,NE,L]

NC, R=301 and L are pretty apparent. The NE is perfect for no-escape also it prevents query string variables from being steered clear of two times. The ^(.*) doesn't need a / generally.

Note: 301 permanent redirect reactions is going to be cached through the browser so obvious your browser cache every occasionally while testing. Otherwise you might not see caused by changes you are making.

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

This redirects every request to world wide web.domain.com including querystring and ask for-uri when the host is not world wide web.domain.com