crabby80 — 2010-08-17T07:31:36-04:00 — #1
I'm not entirely sure how to write RewriteRules yet
I need to redirect anything that goes to mydomain.com/members/NAME
to mydomain.com/members/ view.php?profile_name=NAME
This is currently already in place at the moment, but it doesn't seem to work, is this correct?
RewriteRule ^members/([^/\.]+)?/$ members/$1 [R]
RewriteRule ^members/([^/\.]+)/?$ members/view.php?profile_name=$1
Any help would be much appreciated
Thanks in advance
dklynn — 2010-08-17T23:06:57-04:00 — #2
A strange attempt (pardon me) as you're wrapped around that trailing slash like another recent OP. I would have used:
<font color='"Red"'># RewriteRule ^members/([^/\\.]+)?/$ members/$1 [R]</font>
RewriteRule ^members/([^/.]+)$ members/view.php?profile_name=$1 [L]
The differences are:
By requiring a trailing / then removing it before ANDing with the "real" RewriteRule, you've twisted the logic - and likely introduced the failure point which you must be dealing with.
The dot character (in a character range definition) is NOT a meta-character and does NOT need (and should NOT be) escaped.
You would NOT succeed without ; or } at the end of a PHP statement or block statement so I get upset with people think that the Last flag can be omitted. It's just not logical (to me). Note: Had your first RewriteRule used a Last Flag, it would NOT have been ANDed with the second - it IS important!
Just my preference: I will try to specify exactly what is allowed rather than what is not allowed, i.e., [a-z]+ rather than [^/.]+ to allow only lowercase letters. That will eliminate some error checking in the view.php script before querying the db but it makes the mod_rewrite code do some error checking for me.
crabby80 — 2010-08-18T04:27:57-04:00 — #3
Thank you for your reply it's much appreciated, I'll check it out.
Unfortunatley this was a project I took over so this code was already in place, you should see the code in the rest of the application, it's a shambles!!