Apache in htaccess forbidden Access and Conf in the forbidden Difference

Source: Internet
Author: User

Believe that the person familiar with Web server must be familiar with APAHCE. Believe that the person familiar with Apahce must know the URL Rewrite. Apache's Mod_rewrite module can help people construct a variety of landscaping URLs. There are several ways to use URL Rewrite in Apache: One is to add the appropriate rewriterule (rewrite rules) directly to the httpd.conf, and the other is to add rewriterule (rewrite rules) to. htaccess in the root directory of the Web site. However, it is important to note that the two files added to the URL rewrite rules are slightly different. These differences, for unfamiliar people, are likely to be troubled for a long time.

In the httpd.conf:
(1) The beginning of the Request URI must begin with a slash;
(2) When looking for the cache file, you must add a slash at the beginning;
(3) When using-F or!-f, you must add a slash at the beginning.

In. htaccess, the exact opposite is the case:
(1) The Request URI must not have a slash at the beginning;
(2) When looking for the cache file, do not add a slash at the beginning;
(3) When using-F or!-f, you cannot add a slash at the beginning.

Simply put, in httpd.conf, the URL before and after the rewrite needs to be preceded by a slash "/" when using an absolute path, which means that it starts at the root of the Web site and is not required in. htaccess. Here are two simple examples:

httpd.conf
Rewriterule ^/$/cache/index.html [QSA]
Rewriterule ^/([^.] +) $/cache/$1.html [QSA]
Rewritecond%{document_root}%{request_filename}!-f
Rewriterule ^ (. *) $ dispatch.fcgi [qsa,l]

. htaccess
Rewriterule ^$ cache/index.html [QSA]
Rewriterule ^ ([^.] +) $ cache/$1.html [QSA]
Rewritecond%{request_filename}!-f
Rewriterule ^ (. *) $ dispatch.fcgi [qsa,l]

Perhaps there are more differences, we can also focus on their own research.

For example, one written in the. htaccess.

<ifmodule mod_rewrite.c>#禁止 All Access ....<files ~"^. (htaccess|htpasswd|info.php| (\s) +.md| (\s) +.sql) $">Deny from All</Files># Disable access to Vendor ....<Location/vendor>Deny from All</Location>Options+followsymlinks rewriteengine on Rewritecond%{request_filename}!-D Rewritecond%{request_filename}!-F Rewriterule^ (. *) $ index.php?/$1[Qsa,pt,l]</IfModule>

and written in the httpd.conf.

#ThinkPhp Security Configuration ...<ifmodule mod_rewrite.c>#禁止 All Access ....<files ~"^. (htaccess|htpasswd|info.php| (\s) +.md| (\s) +.sql) $">Deny from All</Files># Disable access to vendor .... composer directory where ...<Location/vendor>Deny from All</Location> <Location/ThinkPhp>Deny from All</Location>Options+followsymlinks rewriteengine on Rewritecond%{document_root}%{request_filename}!-D Rewritecond%{document_root}%{request_filename}!-F Rewriterule^/(. *) $ index.php?/$1[Qsa,pt,l]</IfModule>

Apache in htaccess forbidden Access and Conf in the forbidden Difference

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.