Apache not redirecting encoded urls

I have a problem with Apache doing a 301 redirect with encoded urls. The urls are encoded as they include Hebrew chars.

I’ve done some Googling and found out that there is a know bug with encoded urls and slashes and that I should encode the slash twice so that it becomes ‘%252f’.

Unfortunately none of what I tried worked.

The url that I would like to do the redirect for is the following (Just one Hebrew letter for the sake of simplicity):

www.domain.com/�

so I tried the following the lines in .htaccess:

redirect 301 /%D7 http://www.tagetdomain.com
redirect 301 %2f%D7 http://www.tagetdomain.com <– Slash encoded
redirect 301 %252f%D7 http://www.tagetdomain.com <– Slash double encoded

I also tried may other things that made less to little sense at all but I gave them a try anyhow.

Will appreciate any help with this.
Thanks!

eran,

You’re trying to redirect all three do the (naked) domain?

Please review http://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirect as that has the correct syntax which, unless %whatever is the URI Path, make your code useless.

Once past that, I’ll have to assume that your host “speaks” Hebrew, i.e., Hebrew is an enabled language. If that’s the case (which I expect it would be), then you can merely replace the UNencoded characters in the URI Path with the “plain text” characters … in Hebrew. At least, that’s what would happen inside a character range definition in mod_rewrite.

Regards,

DK

Hi DK,

I wasn’t trying to redirect all three at the same time… only one at a time each, I just wanted to write every variation I tried.

I did the simplest of tests and tried both encoded and unencoded versions.

I created a file called א.html and tried it on my localhost:

http://localhost/&#1488;.html <- This works fine in the browser

the encoded representation of the letter א is %D7%90 so I created

http://localhost/א.html <- This works fine in the browser too

But, if i try redirecting any of the two urls using this in .htaccess:

Redirect 301 /%D7%90.html http://www.tagetdomain.com

or Redirect 301 %D7%90.html http://www.tagetdomain.com

or Redirect 301 /א.html http://www.tagetdomain.com

or Redirect 301 א.html http://www.tagetdomain.com

Apahce will not redirect, and the content of the file will just be displayed in the browser. Using the same .htaccess line on non hebrew files redirects fine.

I also tried replacing the / char with the encoded and double encoded representation as suggested here:

http://serverfault.com/questions/295664/mod-rewrite-not-working-with-url-encoded-values

As you can see in that discussion there is some problem with slash and url encoded chars although I tried every possible variation and still can’t get apahce to redirect the hebrew URLs.

Any thoughts?

eran,

Thoughts? Bah!

Okay, when one tool fails to “play nice,” then I tend to fall back on mod_rewrite (which DOES recognize other character sets but within a character range definition). Please comment out the Redirects and try:

RewriteEngine on

RedirectRule ^&#1488;\\.html$ http://www.tagetdomain.com [L]

OR

RewriteEngine on

RedirectRule ^[&#1488;]\\.html$ http://www.tagetdomain.com [L]

Regards,

DK

Thanks DK, got it working
you did mean RewriteRule not RedirectRule right…?

Not very important but in terms of resources is there any difference between the two approaches?

eran,

OMG! I swear I wasn’t drinking when I wrote that reply!

As you’ve surmised, though, RewriteRule is the correct directive.

Regards,

DK