I tried to create a htaccess file that rewrites, for example the URL from /index.php?type=car&model=audi&color=990000&year=1995 to /index/car/audi/990000/1995.
At the moment i use the following:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+) $1.php?type=$2&model=$3&color=$4&year=$5
The problem is, it works fine when you fill in all the variables, but when you want all cars from "Audi" and keep the color and year empty, the page crashes. How can I change the mod开发者_如何学JAVA so the page won't crash and he get the right vars in the PHP?
At first glance I would change the + to * in your rule. + means One or more while * means zero or more. Also, you might need to make the / optional.
EDIT: Try this:
RewriteRule ^([^/]+)/?([^/]*)/?([^/]*)/?([^/]*)/?([^/]*) $1.php?type=$2&model=$3&color=$4&year=$5
精彩评论