您的条件仅适用于第一条规则。每套RewriteCond
的只适用于紧接的RewriteRule
。所以条件只适用于RewriteRule ^/([^./]+)\.html$ category.php?id=$1
,最后2条规则完全没有条件。
您的条件是将的某些东西重写为,这会导致重写循环。你可能想:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
你的第二和第三个规则将永远不会被应用,因为如果有人请求/some-page.html
第一条规则的正则表达式匹配并重写的URI到/category.php?id=some-page
,那么接下来的规则永远不会匹配因为第一条规则已将URI重写为category.php
。
你的正则表达式匹配一个斜线,因为是一个htaccess文件中重写规则被应用于URI的拥有领先的斜线剥离出来,所以你要这个:
RewriteRule ^([^./]+)\.html$ category.php?id=$1
1, 2和4很容易。 3,不是那么多。你将不得不找出一个独特的方式来表示一个HTML页面作为一个类别,标签或播放。你不能让所有3看起来完全相同,没有办法告诉你想要哪一个。采取:
/something.html
这应该是一个类别?标签?还是玩?谁知道,你的重写规则肯定没有。但是,如果你有一个关键字前言每次,那么你就可以区分:
/category/something.html
/tag/something.html
/play/something.html
而且你的规则看起来像:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/([^./]+)\.html$ category.php?id=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^tag/([^./]+)\.html$ tag.php?id=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^play/([^./]+)\.html$ play.php?id=$1