CraigColes
CraigColes

Reputation: 87

Mod_Rewrite for clean URL

Really simple request. I want my url to look like:

http://localhost/movie/72105

instead of this

http://localhost/movie?id=72105

I currently have this setup going on in my .htaccess file, but it does not seem to be working:

RewriteEngine on
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([a-z\-]+)$ index.php?id=$1 [L]
</IfModule>

Just to clarify aswell, when the mod_rewrite is working successfully, I can still use to retrieve the ID?:

$_GET['id']

Much appreciated for any help.

Upvotes: 1

Views: 141

Answers (2)

undone
undone

Reputation: 7888

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^lab/movie/(\d+)$ index.php?id=$1 [L]
</IfModule>

Now, you can browse http://domain.com/movie/12 and $_GET['id'] will be 12.

Upvotes: 1

helle
helle

Reputation: 11660

I am using this one

Options +FollowSymLinks
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
RewriteBase /
#  Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

you can retrive the id and other parameters (mobvie) by parsing

$_SERVER['REQUEST_URI']

in your index.php than. also see: http://httpd.apache.org/docs/current/mod/mod_rewrite.html

Upvotes: 1

Related Questions