0

我正在尝试将我网站上的 URL 从 .php 重写为 .html,并且我还有一些其他规则会干扰我想做的事情。

下面的代码显示了所有有效的规则,但我有一些扁平的 PHP 页面,我想将它们转换为 .html 页面。一个例子是history.php 到history.html。

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /


##Vendor Pages
RewriteRule ^([^/]+)/([^/]+)/([^.]+)\.html?$ vendors2.php?vendorslug=$3&locationslug=$1&categoryslug=$2 [L,QSA,NC]

##Listing Pages
RewriteRule ^([^/]+)/([^.]+)\.html?$ listings.php?locationslug=$1&categoryslug=$2 [L,QSA,NC]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !^(.*/)?history\.html$ [NC]
RewriteRule ^([^/.]+)\.html?$ $1.php [L,NC]

##Locations Pages
RewriteRule ^([^/.]+)\.html?$ locations.php?locationslug=$1&Submit=Submit [L,QSA,NC]

目前,该代码似乎与其他规则混淆,因为它试图将页面作为“位置页面”返回,因为这些规则。

我需要将几个页面转换为 .html(history.php、news.php、maps.php、resources.php、trivia.php 等)。

任何建设性的帮助表示赞赏。

4

1 回答 1

1

您可能根本不匹配 RewriteCond。您RewriteCond检查文件是否存在可能会被解释为“是/home/username/public_html/history.html.php文件吗?”,这将失败。

我建议不要RewriteCond在你的规则之前包含几个 's,你可以用一个RewriteRule, 在你的##Locations Pages. 类似于以下内容:

RewriteRule (history|news|maps|resources)\.html $1.php [L]

请注意,如果您有很多条目,这可能会导致很长的一行,因此您可以将其拆分为几个规则。

如果您正在寻找“根”中的请求:

RewriteRule ^(history|news|maps|resources)\.html$ $1.php [L]
于 2013-05-30T15:51:06.227 回答