我正在使用.htaccess从我的urls中删除.html扩展名。例如..。
https://www.example.com/work.html > https://www.example.com/work
我希望能够有一个网站显示一个404页(或正确的错误页),如果有人试图访问一个文件/目录,这不是(例如) https://www.example.com/work/new。但这将返回一个500内部服务器错误。
错误行ErrorDocument 500 / .htaccess /500.html不返回该文件(它适用于404、403等)。它返回这个错误...
此外,在尝试使用ErrorDocument处理请求时,遇到了500内部服务器错误。
阿帕奇错误日志显示...
AH00124:由于可能的配置错误,请求超过了10个内部重定向的限制。如有必要,使用'LimitInternalRecursion‘来增加限制。使用“LogLevel debug”获取回溯。
我假设这是因为它本质上是试图在html文件中查找目录(尝试在html文件“work.html”中查找目录“新”),因此返回500server错误而不是404。
下面是我的.htaccess文件。有没有人能帮助我们找到更好的方法来做这件事或者绕过它?
# Disable Directory Listing
Options -Indexes
# X-Robots-Tag
Header set X-Robots-Tag "noindex, nofollow"
# Rewrite Engine
RewriteEngine On
# Root Directory
RewriteBase /
# Remove .html Extension
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP
RewriteRule (.*)\.html$ $1 [R=301]
# Remove index + Reference Directory
RewriteRule (.*)/index$ $1/ [R=301]
# Remove Trailing Slash **If Not Directory**
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# Forward Request To html File, **But Don't Redirect (Bot Friendly)**
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.html [L]
# Errors
ErrorDocument 403 /errors/403.html
ErrorDocument 404 /errors/404.html
ErrorDocument 500 /errors/500.html
发布于 2018-08-31 05:37:17
RewriteRule (.*).html$ $1 R=301
您需要在所有外部重定向上使用L
(last
)标志,以防止进一步处理。例如:
RewriteRule (.*)\.html$ $1 [R=301,L]
此外,请确保禁用了MultiViews
:
Options -Indexes -MultiViews
假设您已经链接到不带扩展名的URL?
https://stackoverflow.com/questions/52104603
复制相似问题