当链接包含破折号时(在loaclhost xampp上),RewriteRule不会工作

时间:2012-02-10 01:28:29

标签: .htaccess url-rewriting

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)。

1 个答案:

答案 0 :(得分:0)

我可以立即想到两种情况会导致不适用此规则:

  1. subpage-with-dash是站点根目录中的目录名称。这将使RewriteCond跳闸并导致跳过规则。
  2. 网址中包含句点。 RewriteRule中的模式 - ^([^\.]+)$) - 排除包含任何句点的网址。因此,如果subpage-with-dash实际上是subpage-with-dash.something,则该规则将不适用。