[英]How to use .htaccess to redirect example.com.tw to example.com?
I have bought two domains, both 'example.com.tw' and 'example.com'. 我已经购买了两个域名,分别是“ example.com.tw”和“ example.com”。 I hope that when a user input 'example.com.tw' in the address bar, it can redirect to 'example.com' automatically.
我希望当用户在地址栏中输入“ example.com.tw”时,它可以自动重定向到“ example.com”。 Below is my try.
下面是我的尝试。
RewriteCond %{HTTP_HOST} ^www\.example\.com\.tw [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L,NE]
The issue is that when a user input the subdomain (Such as: 'news.example.com.tw'), will it redirect correctly? 问题是,当用户输入子域(例如:“ news.example.com.tw”)时,它会正确重定向吗? (Will it redirect to 'news.example.com' successfully?)
(它将成功重定向到“ news.example.com”吗?)
To remove the .tw
TLD: 删除
.tw
TLD:
Assuming both domains point to the same place and any subdomains are simply in subdirectories off the main domains document root (or point to the document root of the main domain itself). 假设两个域都指向同一位置,并且任何子域都位于主域文档根目录之外的子目录中(或指向主域本身的文档根目录)。 Then, in your root .htaccess file:
然后,在您的根.htaccess文件中:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.tw$
RewriteRule ^ http://%1%{REQUEST_URI} [R=302,L]
Replace 302
(temporary) with 301
(permanent) when you are sure it's working OK. 确定可以正常运行时,请用
301
(永久)替换302
(临时)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.