I would like to rewrite the following URL:
http://www.domain.com/cars/cars.php?cars_item=231
To
http://www.domain.com/cars/231/
I have tried the following coding but cannot get it working for some reason.
In sub-folder cars
I placed the .htaccess file which includes:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([0-9]+)\/?$ cars.php?cars_item=$1 [NC]
</IfModule>
Apache is configured properly as I have tried a redirect from one domain to another using an .htaccess file and works fine.
Could someone please explain to me what I'm doing wrong?
This rule should do what you want:
The first rule is in charge of receiving the unfriendly URL and converting it to a friendly URL.
The second rule will redirect it internally not changing the browser URL.
These rules should be placed on the root of your domain in your case the folder before
cars
.You need to do it like this in order to avoid a redirect loop unless you're using a newer version of HTTPD but since I do not know any server specifics I just gave you a generic example.
If all you want is to be able to access:
Without redirecting the original URL then you could just use:
The above rule takes care of receiving the above mentioned URL and send it to the proper handler.