J
J
jorajra2019-02-06 23:36:27
Search Engine Optimization
jorajra, 2019-02-06 23:36:27

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

2 answer(s)
P
Pavel Volintsev, 2019-02-07
@copist

How can I do it right so that there are no negative consequences for either Google or users?

If you make a 301 on the main page, indexing will suffer (all pages will drop out of the search, duplicates will appear, warnings in Google Webmaster - see proof with statistics) and users will not be able to open product pages using old links.
To avoid consequences, you need to make a mapping of old URLs and new URLs so that search robots understand through HTTP 301 that old URLs can be replaced with new ones.
There may be many such links. You will need a redirect map. You can implement it on Apache , on Nginx , you can use your favorite programming language ( example in PHP ).

V
Viktor Taran, 2019-03-04
@shambler81

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]

If you do not require additional conditions, then you do not need cond.
By the way, your rule redirects only 1 character from 1 to 9,
for example, if it is 32, then this redirect will not work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question