NotionCommotion Posted January 25, 2015 Share Posted January 25, 2015 Given the below rules and following browser input: user/joe/x RewriteEngine on RewriteRule ^user/(\w+)/?$ user.php?id=$1 Why wouldn't user/joe/ be matched? resulting in user.php?id=joex Quote Link to comment https://forums.phpfreaks.com/topic/294220-simple-regex-question/ Share on other sites More sharing options...
Drongo_III Posted January 25, 2015 Share Posted January 25, 2015 How's this? Works for me. RewriteEngine on RewriteRule ^user/([^/]+) user.php?id=$1 Quote Link to comment https://forums.phpfreaks.com/topic/294220-simple-regex-question/#findComment-1504147 Share on other sites More sharing options...
Ch0cu3r Posted January 25, 2015 Share Posted January 25, 2015 The reason why your rewriterule will not match the url such as user/joe/x is because of the end anchor character (the dollar sign). When you use both anchor characters in your regex you are asking for an exact match (ie, the regex pattern should find a match from the very first character to the very last character of the url). If you want to allow extra characters in your url then remove the dollar. Quote Link to comment https://forums.phpfreaks.com/topic/294220-simple-regex-question/#findComment-1504151 Share on other sites More sharing options...
NotionCommotion Posted January 26, 2015 Author Share Posted January 26, 2015 Thanks Ch0cu3r, That's right! Guess I once knew that but forgot it. Quote Link to comment https://forums.phpfreaks.com/topic/294220-simple-regex-question/#findComment-1504228 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.