Results 1 to 3 of 3
Thread: Help with RewriteRule
Aug 17, 2010, 04:31 #1
Help with RewriteRule
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
Aug 17, 2010, 20:06 #2
- Join Date
- Feb 2002
- 19 Post(s)
- 2 Thread(s)
A strange attempt (pardon me) as you're wrapped around that trailing slash like another recent OP. I would have used:Code:
RewriteEngine on # RewriteRule ^members/([^/\.]+)?/$ members/$1 [R] RewriteRule ^members/([^/.]+)$ members/view.php?profile_name=$1 [L]
1. 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.
2. The dot character (in a character range definition) is NOT a meta-character and does NOT need (and should NOT be) escaped.
3. 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!
4. 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.
Aug 18, 2010, 01:27 #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!!