views:

24

answers:

3

Hi Guys,

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 so the page won't crash and he get the right vars in the PHP?

Many thanks,

Regards Drewes

A: 

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
David Radcliffe
A: 

Good point about that *, i changed it, but can you explain me how i can make the / optional? I tried some things with ()? around the vars, but it didn't work.

thnx!

Drewes
A: 

Hi David,

Thnx for your example i tried it, but even with several changes i keep getting the error "500-internal-server-error".

When i try RewriteRule ^([^/]*)?/([^/]*)?/([^/]*)?/([^/]*)?/([^/]*) $1.php?type=$2&model=$3&color=$4&year=$5 then i don't get the error, but it still won't work. (I still get page not found when i fill only 2 options) I hope anyone knows how to fix it,

grTz Drewes

Drewes