I have a .htaccess file that in its end I created some 301 redirects. For example:

Redirect 301 /site-building-from-home /
Redirect 301 /%D7%9E%D7%96%D7%99%D7%9F-%D7%AA%D7%9B%D7%A0%D7%99%D7%9D /

For some reason all redirects with an English alias (say, site-building-from-home) works but all these with encoded aliases (Hebrew-to-machine-language) don't.

Do we have an Apache-directives/PCRE expert that can explain this phenomena ?

(Note: I used / instead a domain-name+TLD for flexibility considerations).


As it states in the Apache docs for a mod-alias Redirect:

The old URL-path is a case-sensitive (%-decoded) path ...

So, assuming /%D7%9E%D7%96%D7%99%D7%9F-%D7%AA%D7%9B%D7%A0%D7%99%D7%9D is the actual request as sent from the client, then you will need to match against the literal, percent-decoded (aka URL-decoded), text in the Redirect directive. From your example this would be:

Redirect /מזין-תכנים /

(Make sure your .htaccess file is UTF-8 encoded.)

If you want to match the percent-encoded URL, as sent from the client, then you will need to use mod_rewrite and match against THE_REQUEST server variable (which is not percent-decoded). For example:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /%D7%9E%D7%96%D7%99%D7%9F-%D7%AA%D7%9B%D7%A0%D7%99%D7%9D\ HTTP/
RewriteRule ^ / [R=301,L]

You will need to enable the rewrite engine earlier in your code if not already ie. RewriteEngine On.

However, if you change to using mod_rewrite redirects then it is strongly recommended to change your mod_alias Redirects to use mod_rewrite as well in order to avoid unexpected conflicts.

|improve this answer|||||
  • Instead of moving all ~ 150 redirects to mod-rewrite oriented syntax, do you know a fast way to decode all redirects inside notepad++ or another way to transform all ~ 150 redirects decoded in a single clicks? Will start looking a way now but please tell me if you know anything. – user58733 Sep 27 '16 at 7:58
  • You could try just pasting your code/encoded URLs into an online URL decoder/encoder and hitting the "decode" button - just be careful if there is anything that shouldn't be "decoded". – MrWhite Sep 27 '16 at 8:03
  • Yes, I knew this way a few years ago and also thought something that "doesn't need" to change will be changed --- But, gladly, only the codded aliases was decoded and it worked like a charm and now the 301s are working fine. Thank you! – user58733 Sep 27 '16 at 8:08
  • I used this particular tool: meyerweb.com/eric/tools/dencoder – user58733 Sep 27 '16 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy