سؤال

I've static sub-folders on my server. All i want is the Apache to forward them the right way. With normal English sub-folders, I've no problem. example.com/asd -> /srv/fdr/asd. When the request contains non-ascii letters it convert them like this Büc -> B%C3%BCc, while my folder is named /srv/fdr/Büc (in utf8), the Apache forward it to /srv/fdr/B%C3%BCc.

Any idea on how to change URL path requested encoding ?

Thanks

هل كانت مفيدة؟

المحلول

You can use RewriteMap and the int (internal functions) to create an unescape map (although it's called "escape"). Since this is a RewriteMap, it needs to be in either the server config (httpd.conf) or virtual host config:

RewriteMap unescape int:escape

Now you can use ${unescape:} on your backreference. So if you are matching a URI that has escaped characters, you can wrap your backreference in that in order to unescape. For example:

# Need this to avoid rewrite-looping
RewriteCond %{REQUEST_URI} !^/srv/fdr
RewriteRule ^(.+)$ /srv/fdr/${unescape:$1} [L,NE]

This will take the URI /B%C3%BCc and rewrite it to /srv/fdr/Büc

Also note that if you put the rewrite rule inside your server or virtualhost config, you need to add a / before the (.+) in the regex match.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top