Removing country domain name using mod_rewrite
I have bought both an international domain (.com) and a Brazilian domain (.com.br). I need to redirect people from the Brazilian domain to the international one, so that thewebsite.com.br/contact goes to thewebsite.com/contact. On top of that, I would also like to remove the www both from the Brazilian and international domain names. So that www.thewebsite.com.br/conta开发者_运维知识库ct takes my user to thewebsite.com/contact.
I am using the Drupal .htaccess rewrite rule for removing the www:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
What do you recommend? Adapt this rule to remove the international .br or add another rule on top of this to remove the .br? How would be the final mod_rewrite condition for both removing www and .br from my URLs?
This should work.
<IfModule mod_rewrite.c>
# Enable rewrite
RewriteEngine On
RewriteBase /
# Rewrite .br to international domain
RewriteCond %{HTTP_HOST} ^www.domain.com.br [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
# Rewrite non www. .br to international domain
RewriteCond %{HTTP_HOST} ^domain.com.br [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
# Rewrite www. to non www.
RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
</IfModule>
精彩评论