Using 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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Using mod_rewrite

Post by aceconcepts »

Hi,

I now understand mod_rewrite to a greater extent.

However, I was wondering if anyone could tell me how to re-write my rule so that i can simply declar my variable straight after the domain name

e.g.

What I want to do is re-write: http://www.site.com/registration - where registration would be a variable

At the moment I have to write it like this: http://www.site.com/index/registration - I basically want to get rid of "index".

Here is my rule: RewriteRule (.*)//(.*) $1.php?parameters=$2

Thanks.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Using mod_rewrite

Post by Zoxive »

Most common way to rewrite is done with the following

Code: Select all

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
 
RewriteRule ^(.*)$ index.php/$1 [L]
Rewrites everything to index, then the Front Controller would decide how to set everything.

To answer your question though..

Code: Select all

RewriteRule ([^/]*)$ index.php?param=$1
Matches everything but the /'s
Post Reply