alex_maldinsky2017-04-17 14:15:07
alex_maldinsky, 2017-04-17 14:15:07

301 redict from any nesting, how?

Good afternoon.
Please tell me how to implement a 301 redict from any nesting to without it. For example:
1. site/elektroinstrument/kategorii/perforatory/perforator-m12-ch-202c/ to site/perforator-m12-ch-202c/
2. site/rezak-dlya-plastikovyh-trub/ to site/rezak-dlya- plastikovyh-trub/ (i.e. if there is no nesting, then leave)
3. website/rezaki/rezak-dlya-plastikovyh-trub.html to website/rezak-dlya-plastikovyh-trub
/ remove any nesting and if it ends with .html, then change to /

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Viktor Taran, 2017-04-17

#  если минимум 1 символ до последнего конца строки, и убираем слеш еслион есть.
RewriteCond %{REQUEST_URI} .*(/.+)(|/)$
# то пенренаправить все  на сайт и то что в скобках.
RewriteRule ^(.*)$ http://site.ru%1 [R=301,L]

We get
Although of course you would do well to work with "greedy quantifiers"
there is something to improve here.
Now remove .htnl
RewriteCond %{REQUEST_URI} ^(.+)\.html$
RewriteRule ^(.*)$ %1/ [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question