Answer the question
In order to leave comments, you need to log in
How to correctly write a 301 redirect under a certain condition?
You need to write the 301 redirect correctly. The essence of the problem: there are more than a thousand addresses with goods in the Google index, which look like site.com/number_set from 0 to 9.html. The site engine has changed, and now the products are all in sections. In order to avoid a bunch of 404 errors in the search console, I want to put all these pages on the main one until they fall out of the index.
I found and wrote in .htaccess the following condition
RewriteRule ^[0-9] https://site.com/ [R=301,L]
Redirects seem to work. At least https://site.com/catalog/1.html does not redirect to the main one, which is what we need. But the question is, there is also a RewriteCond line, which is always, or almost always, written before the RewriteRule. Tell me, is it mandatory in this case? How can I do it right so that there are no negative consequences for either Google or users?
Answer the question
In order to leave comments, you need to log in
How can I do it right so that there are no negative consequences for either Google or users?
Revray cond is just an "IF" condition!
For example
RewriteCond %{REQUEST_FILENAME} !-f
Если это не файл
RewriteCond %{REQUEST_FILENAME} !-l
Если это не директория
RewriteCond %{REQUEST_FILENAME} !-d
Если это не файл урлреврайт ( защита от цикла)
RewriteCond %{REQUEST_FILENAME} !/bitrix/urlrewrite.php$
ТО выполнить редирект.
RewriteRule ^(.*)$ /bitrix/urlrewrite.php [L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question