Mobile app version of vmapp.org
Login or Join
Bryan171

: Encoded 301 redirects don't work, only english one does I have a .htaccess file that in its end I created some 301 redirects. For example: Redirect 301 /site-building-from-home / Redirect 301

@Bryan171

Posted in: #Htaccess #Redirects

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).

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Bryan171

1 Comments

Sorted by latest first Latest Oldest Best

 

@Jamie184

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme