301 Redirect (Canonization issues)


I have the .com .net and .org domains for my website. To avoid canonization issues (I think that’s the term) I would like to redirect my .net and .org to my .com.

I have got to this work briefly, with something like this:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc] 

But it won’t work when I include it into my existing .htaccess of:

RewriteEngine on

RewriteRule ^forum/([0-9]+)/([0-9]+)/(.*?).html$ /forum.php?page=thread&pid=$1&p=$2
RewriteRule ^docs/([a-zA-Z0-9_-]+)/(.*?).html$ /docs.php?page=$1
RewriteRule ^docs/([a-zA-Z0-9_-]+)/$ /docs.php?page=$1

How do I incorporate the two? One problem was that any directory (eg. /directory) would just redirect to the index page.

The logic here is: if the domain is not www.domain.com, redirect the request to www.domain.com

That’s not what your code does; what you’re code does is: if the domain starts with domain.com, redirect to www.domain.com
That doesn’t take on any of the .net, .org, etc at all.


RewriteEngine On

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

# all other RewriteRules go here

That should work (does for me) :slight_smile: