simple mod_rewrite

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
invisibled
Forum Contributor
Posts: 112
Joined: Sun Apr 29, 2007 3:35 pm
Location: New Westminster

simple mod_rewrite

Post by invisibled »

Hey everybody,

i've been playing with mod_rewrite to try and get a simple rewrite working but i'm missing something, and its not working.

i have a page that is users/?user=somename and i want it to just be /somename

the somename will be dynamic so it can't be hardcoded. Anybody out there done this before? I already have the following rewrite rules on to get rid of the use of .php file extension

Code: Select all

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: simple mod_rewrite

Post by requinix »

For the extension just use MultiViews. For the somename,

Code: Select all

Options +MultiViews
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)/?$ users/index.php?user=$1 [L]
Post Reply