English 中文(简体)
查阅档案规则
原标题:htaccess file rules

我在座右边有这样的规则:

RewriteRule ^art_(.*).htm$ art_item.php?id=$1

与此类似:art_1.html => art_item.php?id=1

现在,我想补充一下以下几个方面:art_1/5.html => art_item.php?id=1&id2=5

RewriteRule ^art_(.*)/(.*).htm$ art_item.php?id=$1&id=$2

我试图这样做,但服务器投下了404个错误。 什么错误?

最佳回答

首先,你需要仔细了解规则的次序。

wrong order:

RewriteRule ^art_(.*).html$ art_item.php?id=$1
RewriteRule ^art_(.*)/(.*).html$ art_item.php?id=$1&id2=$2

更正次序:

RewriteRule ^art_(.*)/(.*).html$ art_item.php?id=$1&id2=$2
RewriteRule ^art_(.*).html$ art_item.php?id=$1

This is because (.*) also matches (.*)/(.*), since the / is any character matched by ..

Second: there is a difference between .htm and .html, so either be careful or just use .html?, which matches both.

问题回答

The following should cover it assuming id is numeric (it s best to be as exact as possible):

RewriteRule ^art_(d+).htm$ art_item.php?id=$1
RewriteRule ^art_(d+)/(d+).htm$ art_item.php?id=$1&id2=$2

http://www.un.org/Depts/DGACM/index_french.htm





相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签