Home > front end >  Redirection of URLs with non-latin characters
Redirection of URLs with non-latin characters

Time:12-27

I'm having trouble with what seems like a simple redirects, but the separate online tests I've done show interesting results.

URL 1 to redirect:

https://example.com/bg/автор/author-name

Note: автор is author (автор) in Bulgarian language.

Rewrite rule:

RewriteRule ^bg/автор/(.*)$ https://example.com/bg/author/$1 [L,R=301]

Redirects to:

https://example.com/bg/автор/author-name

Instead, I want it to redirect to:

https://example.com/bg/author/author-name

Test online: https://htaccess.madewithlove.com?share=98002622-055d-4656-9100-32bc297a42c8

URL 2 to redirect:

https://example.com/bg/%D0%B0%D0%B2%D1%82%D0%BE%D1%80/author-name

Note: автор is probably also author (автор) in Bulgarian language.

Rewrite rule:

RewriteRule ^bg/%D0%B0%D0%B2%D1%82%D0%BE%D1%80/(.*)$ https://example.com/bg/author/$1 [L,R=301]

Redirects to:

https://example.com/bg/автор/author-name

I want it to redirect to:

https://example.com/bg/author/author-name

Test online: https://htaccess.madewithlove.com?share=66fdb0d9-f5bb-45a7-a60c-24accb924410

I tried to separate URL 1/URL 2 and their rewrite rules in two online tests to be easier to understand, (I will need both URLs to redirect on production site).

All I can see is that part of URL in rewrite rule from first example appears in output URL in second example, even if used in separate tests, like I did. It looks like there is some redirection I am not aware of (higher power) witch redirects between:

автор
автор
%D0%B0%D0%B2%D1%82%D0%BE%D1%80

Can anyone fix my redirect rules, if there is anything wrong with them?

CodePudding user response:

Problem is in URL decoding. When /%D0%B0%D0%B2%D1%82%D0%BE%D1%80/ is decoded it becomes /автор/, which is also decoded and finally becomes /автор/.

URL redirection rule is needed for each case (to achieve successful redirection without redirect chains):

RewriteRule ^bg/%D0%B0%D0%B2%D1%82%D0%BE%D1%80/(.*)$ https://example.com/bg/author/$1 [L,R=301]
RewriteRule ^bg/автор/(.*)$ https://example.com/bg/author/$1 [L,R=301]
RewriteRule ^bg/автор/(.*)$ https://example.com/bg/author/$1 [L,R=301] 
  • Related