Apache mod_rewrite encounters a 404 error in URL rewriting failure caused by special symbols such as % 2f or % 5c (forward and backward slash ).

Source: Internet
Author: User

. Htaccess File

<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfModule>


Http: // localhost/application/home/index/URL/HTTP % 3A % 2f % 2fwww.domain.com % 2 fpage % 2f

When you access the above link, there is always 404, And the rewrite is invalid.

Http: // localhost/application/home/index/URL/http://www.domain.com/page/

XAMPP that I have been using in the local environment, nginx on the server is no problem, but Apache is quite speechless, always 404, changed to the original, but the page can be opened normally without urlencode

After searching online for half a day, I finally found the cause:

If % 2f (/) or % 5c (\) appears in the URL and path_info, it is considered invalid. Apache will directly return "404 (not found) "error.
That is to say, Apache directly rejects the request before calling the mod_proxy or mod_rewrite module, and returns the 404 error.
To prevent cgi security vulnerabilities, especially when path_info is used in the script but no security filtering operation is performed, the vulnerability is easily injected.


There are two solutions. The first one is relatively simple, but requires the server operation permission:

1. Modify the virtual directory configuration of the site

<VirtualHost *:80>    AllowEncodedSlashes On    DocumentRoot "D:/htdocs/localhost"    ServerName localhost</VirtualHost>


Add allowencodedslashes on in configuration and then restart the service.


Ii. Multiple urlencodes

You can link the URL multiple times, usually twice or three times.

I did a test and found that it had to be successful three times.

Http: // localhost/application/home/index/URL/HTTP % 253a % 25252f % 25252fwww.domain.com % 25252 fpage % 25252f

It seems that this method is not practical, and the change is too large.










Apache mod_rewrite encounters a 404 error in URL rewriting failure caused by special symbols such as % 2f or % 5c (forward and backward slash ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.