Richard_Grant Posted September 14, 2014 Share Posted September 14, 2014 I got these 2 rewrites: RewriteRule ^user/([0-9]+)/(.*)/(.*)/ ./board/user.php?ID=$1&FIRSTNAME=$2&LASTNAME=$3 [L,NC] RewriteRule ^user/([0-9]+)/(.*)/(.*) ./board/user.php?ID=$1&FIRSTNAME=$2&LASTNAME=$3 [L,NC] And i want to combine them but when i do this: RewriteRule ^user/([0-9]+)/(.*)/(.*)(/|$) ./board/user.php?ID=$1&FIRSTNAME=$2&LASTNAME=$3 [L,NC] It doesnt work.. when i type this in the url https://www.mysite/board/users.php?ID=1&FIRSTNAME=Richard&LASTNAME=Grant/ the variables are retrieved like this: (has trailing slash) ID="1" FIRSTNAME="Richard/Grant" LASTNAME="" when i type this in the url https://www.mysite/board/users.php?ID=1&FIRSTNAME=Richard&LASTNAME=Grant the variables are retrieved like this: (doesn't have trailing slash) ID="1" FIRSTNAME="Richard" LASTNAME="Grant" Quote Link to comment https://forums.phpfreaks.com/topic/291055-trailing-slash-is-the-devil/ Share on other sites More sharing options...
requinix Posted September 14, 2014 Share Posted September 14, 2014 (edited) RewriteRule ^user/([0-9]+)/(.*)/(.*)(/|$) ./board/user.php?ID=$1&FIRSTNAME=$2&LASTNAME=$3 [L,NC]That last (.*) is going to match everything up to the end of the string, including the slash. When the regex engine has to choose between / and the end of the string, it'll choose the latter because that's already true and it doesn't want to backtrack to match the slash. Be more restrictive than just .* for everything. Even if you want to allow all sorts of characters you know slashes won't be allowed, right? You should also enforce the end of the string, otherwise /1/Richard/Grant/other/stuff will be allowed. RewriteRule ^user/([0-9]+)/([^/]+)/([^/]+)/?$ ./board/user.php?ID=$1&FIRSTNAME=$2&LASTNAME=$3 [L,NC] Edited September 14, 2014 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/291055-trailing-slash-is-the-devil/#findComment-1491032 Share on other sites More sharing options...
Richard_Grant Posted September 14, 2014 Author Share Posted September 14, 2014 RewriteRule ^user/([0-9]+)/(.*)/(.*)(/|$) ./board/user.php?ID=$1&FIRSTNAME=$2&LASTNAME=$3 [L,NC]That last (.*) is going to match everything up to the end of the string, including the slash. When the regex engine has to choose between / and the end of the string, it'll choose the latter because that's already true and it doesn't want to backtrack to match the slash. Be more restrictive than just .* for everything. Even if you want to allow all sorts of characters you know slashes won't be allowed, right? You should also enforce the end of the string, otherwise /1/Richard/Grant/other/stuff will be allowed. RewriteRule ^user/([0-9]+)/([^/]+)/([^/]+)/?$ ./board/user.php?ID=$1&FIRSTNAME=$2&LASTNAME=$3 [L,NC] Works just like i needed! Quote Link to comment https://forums.phpfreaks.com/topic/291055-trailing-slash-is-the-devil/#findComment-1491033 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.