[英]404 page not working for links with trailing slash
我有一个带有404错误页面的网站,在htaccess中设置如下:
ErrorDocument 404 http://www.example.com/error404.php
如果您尝试访问不存在的页面,则此方法很好用:
www.example.com/nonsensepage.php
www.example.com/nonsensepage.htm
但是Google搜索具有以前网站(Joomla网站)的一些旧链接,其格式如下:
www.example.com/index.php/news
而这并没有被我的404页捕获。 相反,它转到我的索引页面并中断页面!
如何确保我的404页面捕获所有错误的URL?
谢谢
编辑:
我已经尝试过重复的问题答案((将AcceptPathInfo关闭),但它似乎对我不起作用。
这就是我的htaccess文件中的所有内容:
DirectoryIndex index.php
AcceptPathInfo Off
CheckSpelling Off
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 month"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
FileETag none
ServerSignature Off
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC]
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
ErrorDocument 404 http://www.example.com/error404.php
我也将对仅剥离任何尾随内容和斜杠并始终指导的解决方案感到满意:
index.php/anything
到index.php或error404.php
您可以在.htaccess的顶部添加以下行,以发送404以斜线显示.php
文件后的所有内容:
AcceptPathInfo Off
或者,您可以使用以下重写规则:
RewriteEngine On
RewriteRule \.php/.+$ [L,NC,R=404]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.