Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can try something like this:</p> <pre><code>RewriteEngine on RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC] RewriteRule (.*) http://www.domain.co.uk/$1 [L,R=301] </code></pre> <p>The important point is to use a <code>RewriteCond</code>ition that works on the HTTP Host header. Simply speaking, if a <code>RewriteCond</code> is placed before a normal <code>RewriteRule</code> then the rule is only used if the the condition matches.</p> <p>The code excerpt above redirects all requests from the <code>.COM</code> to the <code>.CO.UK</code> domain, so if you only need to redirect certain directory, then you need to adjust the rule accordingly, e.g.:</p> <pre><code>RewriteEngine on RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ RewriteRule uk(.*) http://www.domain.co.uk/uk$1 [L,R=301] </code></pre> <p><strong>Edit:</strong> I hope that this will work for you according to your edit.</p> <p>The first rule rewrites <code>http://www.domain.com/uk</code> and <code>http://www.domain.com/uk/anything</code> to <code>http://www.domain.co.uk/uk/anything</code>.</p> <p>The second rule rewrites <code>http://www.domain.co.uk</code> to <code>http://www.domain.co.uk/uk/</code>. </p> <p><strong>Edit 2:</strong> I changed the rule (modified the last one and added another one) to reflect the demand for rewrites on <code>.co.uk/something</code>. If the path starts with <code>uk/</code> then it just passes through, otherwise it gets rewritten to <code>uk/something</code>.</p> <pre><code>RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC] RewriteRule uk($|/.*) http://www.domain.co.uk/uk$1 [L,R=301] RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.uk$ [NC] RewriteRule ^uk/(.*) - [PT,L] RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.uk$ [NC] RewriteRule (.*) http://www.domain.co.uk/uk/$1 [L,R=301] </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload