我遇到了一些 .htaccess 问题。
我想采用以下网址: /index2/内部重写为/index2.html
在我的 .htaccess 文件中,我有:
RewriteEngine On
RewriteRule ^(.*)/$ $1.html [L]
但是 URL evanjerkunica/index2/ 说:在此服务器上找不到请求的 URL /redirect:/index2.html.html.html。
知道为什么这会在内部不断被重写吗?谢谢您的帮助!!
在应用规则之前,您需要检查 html 是否存在。您可以通过以下条件执行此操作:
RewriteEngine On
# extract the pathname into a capture group
RewriteCond %{REQUEST_URI} ^/(.*?)/?$
# test to see if the pathname + .html exists as a file
RewriteCond %{DOCUMENT_ROOT}%1.html -f
# if both conditions are true, apply the rule:
RewriteRule ^(.*?)/?$ $1.html [L]