En magasin, j’ai des catégories et des produits, par exemple. Les catégories sont formées comme
localhost/categories.php?categoryid=***
où categoryid peut être n’importe quel mot.
Les produits sont formés comme
localhost/products.php?categoryid=***&productmanufactor=***&productname=***
où categoryid
, productmanufactor
et productname
peuvent aussi productname
des mots
Donc, je veux réécrire à partir de (exemple):
localhost/car
à localhost/categories.php?categoryid=car
SAUF QUELQUES MOTS (à propos, contacts, etc.)
et
localhost/car/audi/r8
à
localhost/products.php?categoryid=car&productmanufactor=audi&productname=r8
Comment cela peut être fait facilement?
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]
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]
Le code ci-dessous peut aider.
RewriteEngine On RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /products.php?categoryid=$1&productmanufactor=$2&productname=$3 [L] RewriteRule ^([^/]*)$ /categories.php?categoryid=$1 [L]
Consultez également http://www.generateit.net/mod-rewrite/ J’utilise ce site pour générer htaccess, il est simple à utiliser.