Вопрос

I'm trying to redirect all pages of an old domain to a page about that domain on a new domain.

I have built countless sites using the first 3 lines of the code below which redirects anything that is not www.mydomain.co.uk to www.mydomain.co.uk.

In the following 4 lines im trying to redirect all the pages of olddomain.co.uk to a single page on my new domain www.currentdomain.co.uk/page-about-olddomain

RewriteCond   %{HTTPS} !=on
RewriteCond   %{HTTP_HOST}   !^www\.currentdomain\.co\.uk$   [NC]
RewriteRule   ^(.*)$   http://www.currentdomain.co.uk/$1  [R=301,L]

RewriteCond   %{HTTPS} !=on
RewriteCond   %{HTTP_HOST}   ^www\.olddomain\.co\.uk$   [NC]
RewriteCond   %{HTTP_HOST}   ^olddomain\.co\.uk$   [NC]
RewriteRule   ^(.*)$  http://www.currentdomain.co.uk/page-about-olddomain  [R=301,L]

What i want to happen

What i expect to see from the above code is that the page www.olddomain.co.uk/test-page would redirect to www.currentdomain.co.uk/page-about-olddomain.

What actually happens

What i actualy see is the page www.olddomain.co.uk/test-page redirects to www.currentdomain.co.uk/test-page.

I believe this to be a conflict between the 2 sets of RewriteConds

Any help on this would me much appreciated and i'm sure there are other people wanting to do a similar thing.

Thanks

Это было полезно?

Решение 2

I fixed the issue by swapping the order of the rules thanks to @LazyOne and adding the [OR] condition after the first RewriteCond that checks for the olddomain with the www's

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.olddomain\.co\.uk$   [NC,OR]
RewriteCond %{HTTP_HOST} ^olddomain\.co\.uk$   [NC]
RewriteRule ^(.*)$ http://www.currentdomain.co.uk/olddomain-page [R=301,L]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\.currentdomain\.co\.uk$   [NC]
RewriteRule ^(.*)$ http://www.currentdomain.co.uk/$1  [R=301,L]

Другие советы

Order of rules matters. Swap them around -- move first rule (lines 1-3) below 2nd.

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.olddomain\.co\.uk$ [NC]
RewriteCond %{HTTP_HOST} ^olddomain\.co\.uk$ [NC]
RewriteRule ^(.*)$  http://www.currentdomain.co.uk/page-about-olddomain [R=301,L]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\.currentdomain\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.currentdomain.co.uk/$1 [R=301,L]
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top