php - How to use .htaccess to redirect example.com.tw to example.com? -
summary
i have bought 2 domains, both 'example.com.tw' , 'example.com'. hope when user input 'example.com.tw' in address bar, can redirect 'example.com' automatically. below try.
my try
rewritecond %{http_host} ^www\.example\.com\.tw [nc] rewriterule ^ http://www.example.com%{request_uri} [r=301,l,ne]
questions
- is correct above?
- is there better way improve code above?
the issue when user input subdomain (such as: 'news.example.com.tw'), redirect correctly? (will redirect 'news.example.com' successfully?)
to remove .tw
tld:
assuming both domains point same place , subdomains in subdirectories off main domains document root (or point document root of main domain itself). then, in root .htaccess file:
rewriteengine on rewritecond %{http_host} ^(.*)\.tw$ rewriterule ^ http://%1%{request_uri} [r=302,l]
replace 302
(temporary) 301
(permanent) when sure it's working ok.
Comments
Post a Comment