"Go" Apache about mod_rewrite encounters with special symbols such as%2f or%5c (forward and backward slash) causes URL rewrite to fail with 404 problem

Source: Internet
Author: User
Tags urlencode

. htaccess file

[Plain]View Plaincopy
    1. <ifmodule mod_rewrite.c>
    2. Rewriteengine on
    3. Rewritecond%{request_filename}!-d
    4. Rewritecond%{request_filename}!-f
    5. Rewriterule ^ (. *) $ index.php/$1 [qsa,pt,l]
    6. </IfModule>

Http://localhost/Application/Home/Index/index/url/http%3A%2F%2Fwww.domain.com%2Fpage%2F

When accessing the link above, the 404 is always present, and the rewrite is invalid.

http://localhost/Application/Home/Index/index/url/http://www.domain.com/page/

My local environment has been using the XAMPP, the server Nginx no problem, but Apache is very silent, always 404, replaced by the original, do not go through the urlencode but can open the page normally

Online search for half a day, and finally found the reason:

When%2f (/) or%5c (\) appears in the URL and path_info, it is considered an illegal request and Apache will return directly to the "404 (Not Found)" error. In other words, Apache rejects the request directly before calling the Mod_proxy or mod_rewrite module, giving a 404 error. This is done primarily to prevent CGI security vulnerabilities, especially if the script uses path_info but does not do a security filtering operation, it is easy to inject vulnerabilities.

There are two workarounds, the first of which is simpler, but requires the permissions of the server operation:

First, modify the configuration of the site virtual directory

[Plain]View Plaincopy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
    1. <virtualhost *:80>
    2. Allowencodedslashes on
    3. DocumentRoot "D:/htdocs/localhost"
    4. ServerName localhost
    5. </VirtualHost>



Add Allowencodedslashes in the configuration to restart the service after the sentence

Second, multiple UrlEncode

Links can be urlencode multiple times, usually two times, or three times there will be no problem.

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

Http://localhost/Application/Home/Index/index/url/http%25253A%25252F%25252Fwww.domain.com%25252Fpage%25252F

I feel this method is not very practical, the change is too big

Copyright notice: Can be reproduced at will, original not easy please indicate the original source Oh ~ http://blog.csdn.net/zhouzme

"Go" Apache questions about mod_rewrite encountering special symbols such as%2f or%5c (forward and backward slashes) cause URL rewriting to fail with 404 problems

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.