I need to redirect URLs with wrong domains to the correct domain.
Pseudo code example:
if (domain != "www.correctdomain.com")
redirect("www.correctdomain.com")
How can I do this with a .htaccess
file?
If you happen to not have a hosting plan and you would like to redirect your domain to another domain, it can be easily done using Cloudflare.
You can do this with an If directive...
<If "%{HTTP_HOST} != 'www.example.com'">
Redirect / http://www.example.com/
</If>
Or mod_rewrite. See http://httpd.apache.org/docs/current/rewrite/remapping.html
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) http://www.example.com/$1 [L,R,NE]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With