.htaccess rewrite rule ignoring line, multiple GET variables in url

I am trying to do a .htaccess rewrite rule to display 4 different get variables and exclude one line. The string is immutable, i.e. will always remain the same.

Current url:

/car.php?make=bmw&model=z4&year=2006&color=black_metallic

      

It should be like this:

car/bmw-z4-2006-black_metallic-for-sale

      

This I have done so far

RewriteRule ^car/^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ car.php?make=$1&model=$2&year=$3&color=$4

      

Now I need to ignore the -for-sale line at the end of the nice url.

Any help is greatly appreciated!

+3


source to share


2 answers


try it



 RewriteRule ^car/([^/-]+)-([^/-]+)-([^/-]+)-([^/-]+)/?$ car.php?make=$1&model=$2&year=$3&color=$4 [QSA,NC,L]

      

+1


source


Your delimiter is a hyphen, not a forward slash, so yours RewriteRule

should handle appropriately as well:

Options -MultiViews
RewriteEngine On

RewriteRule ^car/^([^-]+)-([^-]+)-([^-]+)-([^-]+) car.php?make=$1&model=$2&year=$3&color=$4 [L,QSA,NC]

      



  • The option is MultiViews

    used Apache content negotiation module

    , which works before mod_rewrite

    and makes the Apache server map to file extensions. So it /file

    may be in the url, but it will serve /file.php

    .
+1


source







All Articles