RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html [NC,L]
这适用于以下链接:
<a href="/subpagewithoutdash">working link (will link to subpagewithoutdash.html)</a>
但它不适用于带破折号的链接:
<a href="/subpage-with-dash">not working link (should link to subpage-with-dash.html)</a>
有任何关于如何解决它的想法?我坐在安装了Xampp的Windows计算机上(localhost)。
答案 0 :(得分:0)
我可以立即想到两种情况会导致不适用此规则:
subpage-with-dash
是站点根目录中的目录名称。这将使RewriteCond
跳闸并导致跳过规则。^([^\.]+)$
) - 排除包含任何句点的网址。因此,如果subpage-with-dash
实际上是subpage-with-dash.something
,则该规则将不适用。