How to rew开发者_开发知识库rite backslash'\'
with slash'/'
on Firefox?
Chrome, IE, Safari, Opera has build browser rewrite backslash with slash.
But Firefox 3.6.13 returns 404 error page.# Why Firefox returns 404 error page?
RewriteCond %{REQUEST_URI} (.*)\\(.*)
RewriteRule .* %1/%2 [R=301,L]
It is Apache and FF bug, https://issues.apache.org/bugzilla/show_bug.cgi?id=35256
Hopefully it'll be fixed in soon feature.
- AllowEncodedSlashes should really be "on" by default and probably even deprecated. ...
- Nowhere the RFCs is a backslash
(\)
listed as a reserved character. Therefore a%5C
should always be decoded the same as%7E
is converted to a tilde(~)
.
To solve it on Apache:
add AllowEncodedSlashes On
in VirtualHost
httpd-vhosts.conf or httpd.conf, and .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)\\(.*)$
RewriteRule .* %1/%2 [R=301,NC,L]
Surprisingly, that seems to be correct behavior. Backslashes are not amongst the characters allowed in a HTTP or HTTPS URL (as per RFC 1738), therefore they should be escaped. Note that the RFC explicitly mentions backslash as an unsafe character:
Other characters are unsafe because gateways and other transport agents are known to sometimes modify such characters. These characters are "{", "}", "|", "\", "^", "~", "[", "]", and "`".
All unsafe characters must always be encoded within a URL.
In other words, Firefox is doing the correct thing, even if it breaks pages which are incorrectly using backslashes (mostly from confusing URL syntax with Windows path syntax). Other browsers are trying to read the page author's mind, and they convert the backslashes to forward slashes before sending the request; whether this is a Good Thing is a matter of opinion.
Did you try to match on the escaped version of the backslash - %5C
?
精彩评论