I’m no .htaccess expert, but I’ve tried a few different things to redirect a domain to no avail.
I’ve got a UK and US domain…some US pages have uk extension, and need to be pointed to the proper UK domain:
www.domain.com/uk needs to be rewritten to www.domain.co.uk/uk
Ex. If someone types in www.domain.com/uk/about it will be rewritten as www.domain.co.uk/uk/about
Edit: Paths with /uk should be rewritten
So www.domain.com/uk and www.domain.co.uk should be rewritten to www.domain.co.uk/uk/
You can try something like this:
The important point is to use a
RewriteCondition that works on the HTTP Host header. Simply speaking, if aRewriteCondis placed before a normalRewriteRulethen the rule is only used if the the condition matches.The code excerpt above redirects all requests from the
.COMto the.CO.UKdomain, so if you only need to redirect certain directory, then you need to adjust the rule accordingly, e.g.:Edit: I hope that this will work for you according to your edit.
The first rule rewrites
http://www.domain.com/ukandhttp://www.domain.com/uk/anythingtohttp://www.domain.co.uk/uk/anything.The second rule rewrites
http://www.domain.co.uktohttp://www.domain.co.uk/uk/.Edit 2: I changed the rule (modified the last one and added another one) to reflect the demand for rewrites on
.co.uk/something. If the path starts withuk/then it just passes through, otherwise it gets rewritten touk/something.