[英]Redirect url with/without .php extension to index.php using htaccess
我使用Shephertz的非常基本的URL路由机制来路由我的页面。 但是我遇到了文件扩展名的问题。
如果我加载www.example.com/register
,则得到index.php
,但保留URL。
但是,如果我加载www.example.com/register.php
,它不会将我发送到index.php
,而是保留URL。 怎么会?
这是我的.htaccess
文件,适用于非扩展名:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
如何将两者结合起来? 我希望将它们都标记为蓝色...
要将所有外部php请求重定向到404,您可以在.htaccess中使用以下规则:
RewriteCond %{THE_REQUEST} /.+\.php [NC]
RewriteRule ^ - [L,R=404]
我自己使用RewriteCond
和RewriteRule
解决了这个问题。 这是我的.htaccess
现在的样子:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} /.+\.php [NC]
RewriteRule ^ index.php [QSA,L]
现在,我可以使用Shephertz的路由机制将所有带有.php文件扩展名的URL重定向到自定义404页面。
这是404页:
这是没有.php文件扩展名的页面
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.