A
A
Andrey Petrov2013-12-11 16:39:21
Regular Expressions
Andrey Petrov, 2013-12-11 16:39:21

Redirect for specific links. Problem with RewriteRule

Hello.
I ask you to help with the correct formulation of the condition in .htaccess.
In a nutshell :
The site mysite.ru (Site 1) had its domain name changed to http://old.mysite.ru, and the name mysite.ru was assigned to a new site (Site 2).
Part of the materials from Site 1 was not transferred to Site 2, and the task is to ensure that these materials indexed by search engines with links like " http://mysite.ru/content/view/any_integer_number/11/ " open, but, of course, already on links like " http://old.mysite.ru/content/view/any_integer_number/11/ "
At the root of Site 2 in .htaccess I write:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite\.ru\/content\/view\/([0-9]+)\/11\/$ [NC]
RewriteRule ^(.*)$ http://old.mysite.ru/content/view/$1/11/ [L]

But, you see, something was too clever with the syntax and redirection does not occur.
Give me the right idea, please.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Eugene, 2013-12-11
@Nc_Soft

You will never have such an HTTP_HOST, use THE_REQUEST

S
Sergey, 2013-12-11
@Tikson

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite\.ru$ [NC]
RewriteRule ^(.*)$ old.mysite.ru/$1 [R=301,L]
Redirect from mysite.ru to old.mysite. ru. If the first two lines are uncommented, then they do not need to be written again.

S
Sergey Kazarinov, 2013-12-11
@serkaz

Get the working code.

RewriteEngine On
RewriteCond %{REQUEST_URI} /content/view/([0-9]+)/11/$ [NC]
RewriteRule ^(.*) http://old.mysite.ru/$1 [R=301,L]

HTTP_HOST - returns mysite.ru, www.mysite.ru, subdomain.mysite.ru. REQUEST_URI - Returns everything after the domain.
Backslashes before slashes are not needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question