我的网站有一个404错误页面,在htaccess中设置如下:
ErrorDocument 404 http://www.example.com/error404.php
如果您尝试访问不存在的页面,这可以正常工作:
www.example.com/nonsensepage.php
www.example.com/nonsensepage.htm
但谷歌搜索有一些来自旧网站(Joomla网站)的旧链接,其格式如下:
www.example.com/index.php/news
这不是我的404页面。相反,它会进入我的索引页面并打破页面!
如何确保我的404页面捕获所有错误的网址?
由于
编辑:
我已经尝试了重复的问题答案,(将AcceptPathInfo添加为Off)但它似乎对我没用。
这是我在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
答案 0 :(得分:4)
您可以在.htaccess的顶部添加此行,以便在.php
个文件的斜杠之后发送404以获取任何内容:
AcceptPathInfo Off
或者您可以使用此重写规则:
RewriteEngine On
RewriteRule \.php/.+$ [L,NC,R=404]