404 页面不适用于带有尾部斜杠的链接
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 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/ [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 顶部添加此行,以便为 .php
文件的斜杠后的任何内容发送 404:
AcceptPathInfo Off
或者你可以使用这个重写规则:
RewriteEngine On
RewriteRule \.php/.+$ [L,NC,R=404]
我有一个带有 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 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/ [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 顶部添加此行,以便为 .php
文件的斜杠后的任何内容发送 404:
AcceptPathInfo Off
或者你可以使用这个重写规则:
RewriteEngine On
RewriteRule \.php/.+$ [L,NC,R=404]