Apache.htaccess: how to rewrite backslash using slash in Firefox?

How to rewrite backslash '\' with slash '/' in Firefox?

Chrome, IE, Safari, Opera has a built-in browser rework with a backslash.
But Firefox 3.6.13 returns a 404 error page.

 # Why Firefox returns 404 error page? RewriteCond %{REQUEST_URI} (.*)\\(.*) RewriteRule .* %1/%2 [R=301,L] 
+4
source share
2 answers

This is an Apache and FF bug, https://issues.apache.org/bugzilla/show_bug.cgi?id=35256
Hope this will be fixed soon.

  • AllowEncodedSlashes really should be "on" by default and maybe even deprecated ....
  • Nowhere is RFC a backslash (\) specified as a reserved character. Therefore a %5C
    should always be decoded in the same way that %7E converted to tilde (~) .

To solve this problem on Apache:
add AllowEncodedSlashes On to VirtualHost httpd-vhosts.conf or httpd.conf and .htaccess:

 RewriteEngine On RewriteCond %{REQUEST_URI} ^(.*)\\(.*)$ RewriteRule .* %1/%2 [R=301,NC,L] 
+2
source

Surprisingly, this seems to be correct behavior. Backslashes are not among the characters allowed in the HTTP or HTTPS URL (as per RFC 1738 ), so they must be escaped. Note that the RFC explicitly mentions a backslash as an unsafe character:

Other characters are unsafe because gateways and other transport agents are known to sometimes change such characters. These characters are "{", "}", "|", "\", "^", "~", "[", "]" and "` ".

All unsafe characters must always be encoded in the URL.

In other words, Firefox does the right thing even if it crashes pages that use backslashes incorrectly (mainly due to confusing URL syntax with Windows path syntax). Other browsers try to read the mind of the author of the page, and they convert the backslash to forward slashes before sending the request; whether it is a good thing, it is a matter of opinion.

Have you tried matching the escaped backslash - %5C ?

0
source

Source: https://habr.com/ru/post/1338270/


All Articles