简体   繁体   English

htaccess重写规则,防止访问新添加的php文件

[英]htaccess rewrite rule preventing access newly added php files

I have a website with htaccess file. 我有一个带有htaccess文件的网站。 the htaccess has lot of codes. htaccess有很多代码。 when I create a new php file it redirects to another page. 当我创建一个新的php文件时,它会重定向到另一个页面。 so I checked my htaccess file and remove a one line of code 所以我检查了htaccess文件并删除了一行代码

RewriteRule ^.*\.{1}(htm|html|php)\/?   index.php [L,QSA,NC]

after that the file can can able to access diretly. 之后,该文件可以直接访问。 can anyone know the meaning of above htacess and how can it effect for newly added php files. 谁能知道上述htacess的含义,以及它如何影响新添加的php文件。

This rule: 这条规则:

 RewriteRule ^.*\.{1}(htm|html|php)\/?   index.php [L,QSA,NC]

is silently forwarding every request URI with extension .php OR .htm OR .html to index.php 正在以扩展名.php.htm.html将每个请求URI静默转发到index.php

So even if you add a new .php above regex ^.*\\.{1}(htm|html|php)\\/? 因此,即使您在正则表达式^.*\\.{1}(htm|html|php)\\/?之上添加新的.php ^.*\\.{1}(htm|html|php)\\/? will match and request for the newly created file will still be forwarded to index.php 将匹配,并且对新创建文件的请求仍将转发到index.php

PS: This rule doesn't make lot sense though a similar looking rule is used in many front controllers like Wordpress, CodeIgnitor, Cake etc frameworks. PS:尽管在许多前端控制器(如Wordpress,CodeIgnitor,Cake等框架)中使用了相似的外观规则,但该规则没有多大意义。

Reference: Apache mod_rewrite Introduction 参考: Apache mod_rewrite简介

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM