Link to home
Start Free TrialLog in
Avatar of user_x
user_x

asked on

Mod_rewrite with no suffix - but wont pass variable

I am using mod rewrite to make a url easier to enter. The idea is to call the file with parameters with the short url. I have a version that allows this url:
http://example.com/members/members.php?uid=00000
to be entered as this url:
http://example.com/members/00000/
but I need a user to be able to enter with and without a trailing slash
http://example.com/members/00000

I can't decide how to add the second rule or combine them. When i remove the slash for the suffix, it errors out to 404. Anyone have a good idea?
RewriteBase /members/
RewriteEngine On
RewriteRule ^([^/]*)/$ members.php?uid=$1 [L]

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of David S.
David S.
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of user_x
user_x

ASKER

Thanks for the post, it didn't work with either trailng slash or non-trailing slash. Tried the ? mark addtion as a second rule too, no dice.

Thanks,
userx
Try it without using RewriteBase:
RewriteEngine On
RewriteRule members/([^/]*)/?$ members.php?uid=$1 [L]

Open in new window

Avatar of user_x

ASKER

Still a no go, sorry. It works with the original rule but not without the trailing slash. With those two suggestions, it does not get the url for the variable.
RewriteRule ^(.*)$ members.php?uid=$1 [L,QSA]

That will rewrite 0000/  -> members.php?uid=0000/ - not sure if it hurts.

Btw, for debugging you can enable Rewrite Logging in the the server or virtualhost context.
RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9
Avatar of user_x

ASKER

I used Kravimir's first suggestion last night but had a mistake in the expression. I ended up using this:

RewriteRule ^([0-9-]+)/?$ members.php?uid=$1 [L]

Thanks Kravimir and thank to everybody that helped.
Avatar of user_x

ASKER

Thanks, that got it after all.