James Cocker
James Cocker

Reputation: 157

.htaccess Redirect .net/.org/.info to .com for ANY domain name

Struggling to work out how to use Apache redirects in .htaccess to redirect ANY domain to it's .com.

e.g.:

...

It needs to work with any domain, so the answer can't include "example.com" etc.

Something like this:

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

But that's not working, it's losing the middle bit of the domain (e.g. "domain1").

Upvotes: 0

Views: 399

Answers (1)

Walf
Walf

Reputation: 9348

That should work except perhaps the OR is breaking it (you have no more RewriteConds).

I would write it as

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

Upvotes: 1

Related Questions