문제

We're in the process of switching our current site from a multiple domain configuration into a single domain, multiple folder format. i.e.

.co.uk/<uri> is becoming .com/en-gb/<uri>

.com/<uri> is becoming .com/en-us/<uri>

I'm hoping that I'll be able to handle this via a couple of well-crafted .htaccess rules, but I'm not sure of code I'm going to need to achieve this. Can you help?

(PS, I've left the actual domain blank, as we only need to test for the TDL, not the entire domain - although whatever the original domain was need to stay the same, with only the TLD changing - i.e. whatever.co.uk would redirect to whatever.com/en-gb/, whatever2.co.uk would redirect to whatever2.com/en-gb/, and whatever.com would redirect to whatever.com/en-us/)

도움이 되었습니까?

해결책

add the following directives to your .htaccess:

RewriteCond %{HTTP_HOST} (.+)\.co\.uk$
RewriteRule (.*) http://%1.com/en-gb/$1 [R=301,L,QSA]

RewriteCond %{HTTP_HOST} \.com$
RewriteCond %{REQUEST_URI} !^/(en-us|en-gb)/
RewriteRule (.*) /en-us/$1 [R=301,L,QSA]

if you have so many domain TLDs, you maybe want to use RewriteMap to avoid duplicating the first rule for every TLD, RewriteMap will map TLD to Uri string (ex: .co.uk to en-gb),

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top