Rewrite a link, mod_rewrite

In shop, I have categories and products, for example. Categories are formed as

localhost/categories.php?categoryid=***

where categoryid can be ANY WORD.

Products are formed as

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

where categoryid, productmanufactor and productname can be any words too

So I want to rewrite from (example):

localhost/car to localhost/categories.php?categoryid=car EXCEPT SOME WORDS (about, contacts, etc)

and

localhost/car/audi/r8 

to

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

How this can be done easily?

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]

Upvotes: 2

Views: 100

Answers (2)

Mihai Iorga
Mihai Iorga

Reputation: 39724

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]

Upvotes: 4

VibhaJ
VibhaJ

Reputation: 2256

Below code may help.

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

Also check http://www.generateit.net/mod-rewrite/ i am using this site to generate htaccess, it is simple to use.

Upvotes: 2

Related Questions