Reputation: 157
Struggling to work out how to use Apache redirects in .htaccess to redirect ANY domain to it's .com.
e.g.:
domain1.org >> domain1.com
domain2.net >> domain2.com
...
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
Reputation: 9348
That should work except perhaps the OR
is breaking it (you have no more RewriteCond
s).
I would write it as
RewriteCond %{HTTP_HOST} ^(?:www\.)?+(.+?)\.(?!com$)[^.]+$ [NC]
RewriteRule .* http://%1.com/$0 [R=301,NE,L]
Upvotes: 1