问题描述
我已经购买了国际域名 (.com) 和巴西域名 (.com.br).我需要将人们从巴西域重定向到国际域,以便 thewebsite.com.br/contact 转到 thewebsite.com/contact.最重要的是,我还想从巴西和国际域名中删除 www.这样 www.thewebsite.com.br/contact 会将我的用户带到 thewebsite.com/contact.
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/contact takes my user to thewebsite.com/contact.
我正在使用 Drupal .htaccess 重写规则来删除 www:
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]
你有什么推荐?调整此规则以删除国际 .br 或在此之上添加另一条规则以删除 .br?从我的 URL 中删除 www 和 .br 的最终 mod_rewrite 条件是什么?
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?
推荐答案
这应该可行.
<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>
这篇关于使用 mod_rewrite 删除国家域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!