简体   繁体   English

禁用URL中的匹配目录

[英]Disable matching directories in URL

I have wrote simple application based on MVC with simple router. 我用简单的路由器编写了基于MVC的简单应用程序。 Every request is sending to index.php and matching to correct controller but for example when I have "/controller" in URL - server is matching this to directory "controller" not to index.php. 每个请求都发送到index.php并匹配到正确的控制器,但是例如当我在URL中有“ / controller”时-服务器会将其匹配到目录“ controller”而不是index.php。 Is any posibility to disable matching directory which exists on server ? 是否有可能禁用服务器上存在的匹配目录?

Here is my .htaccess 这是我的.htaccess

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [NC,L]

Remove 去掉

RewriteCond %{REQUEST_FILENAME} !-d

Then /controller will also be rewritten to index.php 然后, /controller也将被重写为index.php

Explanation: The RewriteRule will only be applied when the 2 Conditions ( RewriteCond ) before match. 说明:仅当两个条件( RewriteCond )匹配之前,才应用RewriteRule And one of the Conditions checks if the current Path isn't a existing directory. 条件之一将检查当前Path是否不是现有目录。 So if you have a directory controller the condition won't match and the rewrite rule is not applied --> Request is accessing directly the controller folder 因此,如果您有目录controller那么条件将不匹配并且重写规则将不适用->请求正在直接访问控制器文件夹

See also mod_rewrite documentation 另请参见mod_rewrite文档

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

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