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 Answer 1

1
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.

Sign up to request clarification or add additional context in comments.

1 Comment

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.