RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /products.php?brandid=27&pname=$1 [NC]

The above works only for branid=27 and If I include mutilple statements, LIKE

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /products.php?brandid=27&pname=$1 [NC]
RewriteRule ^(.*)$ /products.php?brandid=42&pname=$1 [NC]
RewriteRule ^(.*)$ /products.php?brandid=47&pname=$1 [NC]

it will also run for brandid 27,
I tried lots of stuff but wont able to rewrite rules for mutiple brandid.

For Example:
The url http://www.3gphone.in/products.php?brandid=27&pname=Acer redirects http://www.3gphone.in/Acer

Recommended Answers

All 11 Replies

RewriteEngine On
RewriteRule ^brandid/([^/]*)/([^/]*)$ /products.php?brandid=$1&pname=$2 [L]

Above code will rewrite

http://www.3gphone.in/brandid/27/Acer

to

http://www.3gphone.in/products.php?brandid=27&pname=Acer

If your coding is fetching list from brandid then you have to pass it in URL.

Thanks for the reply..
Here it is the complete code..

Options +FollowSymLinks
Options +Indexes
RewriteEngine on

RewriteCond %{HTTP_HOST} ^3gphone\.in$ [NC]
RewriteRule ^(.*)$ http://www.3gphone.in/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /products.php?brandid=27&pname=$1 [NC]

But I need like http://www.3gphone.in/Acer not http://www.3gphone.in/brandid/27/Acer. Is it possible ?? and second thing CSS is not working..

Okay.The rule is :

RewriteRule ^([^/]*)$ /products.php?pname=$1 [L]

http://www.3gphone.in/Acer TO http://www.3gphone.in/products.php?pname=Acer
But as i said before if you want this url you can not use brandid in coding.

Place that rule and let me know output.

But I have to use both brandid and pname.. Coz, both query string variables are using to fetch data from database.. Again, I am asking, using both variable and Can I create http://www.3gphone.in/Acer

No..
If you don't pass both variable you can't use brandid in coding.

There is one option just pass pname(Acer) and on top of page use select query and get brandid from database table having model 'Acer'.

And if you want SEO friendly url then you have to also save seo friendly product name in php. space is not SEO friendly.
http://www.3gphone.in/Lemon IT 20717 should be http://www.3gphone.in/lemon-it-20717

Refere this link http://htmlblog.net/seo-friendly-url-in-php/ for php function.

No..
If you don't pass both variable you can't use brandid in coding.

There is one option just pass pname(Acer) and on top of page use select query and get brandid from database table having model 'Acer'.

And if you want SEO friendly url then you have to also save seo friendly product name in php. space is not SEO friendly.
http://www.3gphone.in/Lemon IT 20717 should be http://www.3gphone.in/lemon-it-20717

Refere this link http://htmlblog.net/seo-friendly-url-in-php/ for php function.

Thanks, Now I understand, but my CSS is not working. What should I Do ??

Can you post live URL that you are referring?

Dont give relative path use absolute path while including css or images.
e.g. http://www.3gphone.in/css.css

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.