2

例如,在商店中,我有类别和产品。类别形成为

localhost/categories.php?categoryid=***

其中 categoryid 可以是任何单词。

产品形成为

localhost/products.php?categoryid=***&productmanufactor=***&productname=***

where categoryid,productmanufactorproductname可以是任何词

所以我想从(示例)重写:

localhost/car除了localhost/categories.php?categoryid=car某些词(关于、联系人等)

localhost/car/audi/r8 

localhost/products.php?categoryid=car&productmanufactor=audi&productname=r8

这怎么能轻松完成?

htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^about$           about.php [NC,L]
RewriteRule ^contact$         contact.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$            categories.php?categoryid=$1 [NC,L]
4

2 回答 2

4
RewriteRule ^(.*)/(.*)/(.*)$  products.php?categoryid=$1&productmanufactor=$2&productname=$3 [NC,L]
RewriteRule ^about$           about.php [NC,L]
RewriteRule ^contact$         contact.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$            categories.php?categoryid=$1 [NC,L]
于 2012-09-21T11:56:12.350 回答
2

下面的代码可能会有所帮助。

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /products.php?categoryid=$1&productmanufactor=$2&productname=$3 [L]
RewriteRule ^([^/]*)$ /categories.php?categoryid=$1 [L]

还要检查http://www.generateit.net/mod-rewrite/我正在使用这个站点来生成 htaccess,它使用起来很简单。

于 2012-09-21T11:59:58.450 回答