-1

I have file organised like this -

  • www.mysite.com/cars/ford/ford.php
  • www.mysite.com/cars/bmw/bmw.php

I want users to be able to visit these pages without specifying the xyz.php file at the end.

  • www.mysite.com/cars/ford
  • www.mysite.com/cars/bmw

What do I used for a rewrite rule that well let users visit pages using that format?

Jim_CS
  • 4,082
  • 13
  • 44
  • 80
  • That's a common scenario. Have you looked at the [mod-rewrite tag wiki](http://stackoverflow.com/tags/mod-rewrite/info) yet? Where did you stumble on writing the rules? – mario Aug 11 '12 at 17:56

2 Answers2

1

.htaccess

RewriteRule /cars/(.*)$ /cars/$1/$1.php [L]
HappyTimeGopher
  • 1,377
  • 9
  • 14
1

Given that you change all your links to the www.mysite.com/cars/ford form, you need to put this in the htaccess file in your document root:

RewriteEngine On
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule ^/?cars/([^/])/?$ /cars/$1/$1.php [L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220