views:

24

answers:

1

HI guys.

Im using mod_rewrite to do some redirects on a web site.

I want to be able to do the following mySite.com/ -> Goto Home mySite.com/foo -> Goto redirect.php and redirect acordingly.

My redirect rule was

RewriteRule (^\w*$) redirect.php?url=$1 [NC]

But im oviously missing something because when I go tomySite.com/ I get sent to redirect.php

I need a regex that allow lower and upper case letters, as well as underscores but it has to ignore "empty" strings so when I go to mySite.com/ the index file is displayed.

Any help?

Thanks!

+1  A: 
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^index.php index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ redirect.php?url=$1 [NC]

This might work. By the way, you don't have to use () in regex to get $1 which returns everything by default.

Mikulas Dite
This Works fine but if I dont use () on the last rule, I dont get the $1 parameter working. Tried it both ways and had it working WITH the ().Tks a lot!
Bathan