mod_rewrite

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

mod_rewrite

Post by Benjamin »

Hi I am having trouble figuring out how to set up the htaccess file. This is what I have.

Code: Select all

RewriteEngine on
Options +FollowSymlinks
RewriteBase /projects/cms/

RewriteEngine on
RewriteRule ([^/]+)\.html$   index.php?car=$1
RewriteRule ([^/]+)\.html$   description.php?vehicle=$1
If someone clicks on a link like http://mydomain/car/13.html it is supposed to display a list of all the cars available for the category.

If someone clicks on a link like http://mydomain/vehicle/13.html it is supposed to show the details on that vehicle.

What it is actually doing though is showing the details if you go to the first url though.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your regex is passing through.

I think you may need the [L] modifier (last)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Changed to:

Code: Select all

RewriteEngine on
Options +FollowSymlinks
RewriteBase /projects/cms/

RewriteEngine on
RewriteRule ([^/]+)\.html$   index.php?car=$1 [L]
RewriteRule ([^/]+)\.html$   description.php?vehicle=$1
Thanks feyd, that solved the first problem, however going to:

http://domainname/description/12.html is still getting routed to the index page.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your regex needs to be tweaked to understand what to match and what not to.. after you fix that, you can actually lose the [L]
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Can you help me? I have never learned regex.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Nevermind I figured it out.

Code: Select all

RewriteEngine on
Options +FollowSymlinks
RewriteBase /projects/cms/

RewriteEngine on
RewriteRule ^car/([^/]+)\.html$   index.php?car=$1
RewriteRule ^description/([^/]+)\.html$   description.php?vehicle=$1
Post Reply