Apache about mod_rewrite encountering a special symbol such as%2f or%5c (forward and backward slash) causing URL rewrite to fail with 404 problem

Source: Internet
Author: User
Tags urlencode

. htaccess file

<ifmodule mod_rewrite.c>%{request_filename}-%{request_filename}-^ (. *) $ index.php/$1 [Qsa,pt,L]</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

<virtualhost *:80>    allowencodedslashes    on "d:/htdocs/localhost"    ServerName localhost</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

Apache about mod_rewrite encountering a special symbol such as%2f or%5c (forward and backward slash) causing URL rewrite to fail with 404 problem

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.