E
E
eugene1592021-08-16 23:01:03
Apache HTTP Server
eugene159, 2021-08-16 23:01:03

How to write a RewriteRule for such a link?

The site has such a link (yes, with spaces, brackets and Cyrillic):

https://my-site.ru/articles/ (текст вначале списка продукции)/

I want to write a redirect for her, but I can't. Here is what I have tried:
RewriteRule "^articles/ (текст вначале списка продукции)/$" /articles/ [R=301,NC,L]
RewriteRule ^articles/\ (текст\ вначале\ списка\ продукции)/$" /articles/ [R=301,NC,L]
RewriteRule ^articles/%20(текст%20вначале%20списка%20продукции)/$" /articles/ [R=301,NC,L]
RewriteRule ^articles/%20%28%D1%82%D0%B5%D0%BA%D1%81%D1%82%20%D0%B2%D0%BD%D0%B0%D1%87%D0%B0%D0%BB%D0%B5%20%D1%81%D0%BF%D0%B8%D1%81%D0%BA%D0%B0%20%D0%BF%D1%80%D0%BE%D0%B4%D1%83%D0%BA%D1%86%D0%B8%D0%B8%29/$ /articles/ [R=301,NC,L]

But none of this works - there is simply no redirect. How to write a redirect for such a complex link?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-08-16
@eugene159

RewriteRule "^articles/ (текст вначале списка продукции)/$" /articles/ [R=301,NC,L]
RewriteRule ^articles/\ (текст\ вначале\ списка\ продукции)/$" /articles/ [R=301,NC,L]

You also need to escape the parentheses and it will be fine.
RewriteRule "^articles/ \(текст вначале списка продукции\)/$" /articles/ [R=301,L]
RewriteRule ^articles/\ \(текст\ вначале\ списка\ продукции\)/$ /articles/ [R=301,L]

When saving the file, make sure that the encoding is UTF-8 without BOM.
RewriteRule ^articles/%20%28%D1%82%D0%B5%D0%BA%D1%81%D1%82%20%D0%B2%D0%BD%D0%B0%D1%87%D0%B0%D0%BB%D0%B5%20%D1%81%D0%BF%D0%B8%D1%81%D0%BA%D0%B0%20%D0%BF%D1%80%D0%BE%D0%B4%D1%83%D0%BA%D1%86%D0%B8%D0%B8%29/$ /articles/ [R=301,NC,L]

The RewriteRule receives a string as input after %XX has been decoded.
In its original form, the string with %XX can be found in the %{THE_REQUEST} variable.
RewriteCond %{THE_REQUEST} "^\S+ /articles/%20\(%D1%82%D0%B5%D0%BA%D1%81%D1%82%20%D0%B2%D0%BD%D0%B0%D1%87%D0%B0%D0%BB%D0%B5%20%D1%81%D0%BF%D0%B8%D1%81%D0%BA%D0%B0%20%D0%BF%D1%80%D0%BE%D0%B4%D1%83%D0%BA%D1%86%D0%B8%D0%B8\)/[ ?]"
RewriteRule ^ /articles/ [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question