I've the next Web addresses which I have to rewrite: product.php?iata=TV&product=12345 to product/Televison/TV/The new sony-Bravia/12345


product-list.php?iata=TV to product-list/Television/TV

I've the next rewrite rules during my htaccess file:

RewriteRule [^/]+/([A-Za-z]+)/[^/]+/([0-9]+) product.php?iata=$1&product=$2 [L,QSA,NC]
RewriteRule [^/]+/([A-Za-z]+) product-list.php?iata=$1 [L,QSA,NC]

but they are not effective properly. Please can anybody help.

Also, let's say product-list.php also had two query vars? Would the rule conflict using the rule of product.php?


Put this code inside your .htaccess file:

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteRule ^product-list/[^/]+/(.*)$ product-list.php?iata=$1 [L,QSA,NC]
RewriteRule ^product/[^/]+/([^/]+)/[^/]+/(.*)$ product.php?iata=$1&product=$2 [L,QSA,NC]

Do this:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^product/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)$ product.php?iata=$2&product=$4 [QSA,NC,L]
RewriteRule ^product-list/([^/\.]+)/([^/\.]+)$ product-list.php?iata=$2 [QSA,NC,L]

Let me know whether it works

Two hints:

If you are not inside a located atmosphere (= whether it's your personal server and you will customize the virtual hosts, not just the .htaccess files), use the RewriteLog directive: it allows you to find such problems:

# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On

My personal favorite tool to check on for regexp:

http://www.quanetic.com/Regex (be sure to choose ereg(POSIX) rather than preg(PCRE)!)