backyard Posted March 15, 2009 Share Posted March 15, 2009 I've been using a redirect on my site for years without issue. Someone registers a username with an underscore and now for the username with the underscore doesn't work. Options +FollowSymlinks Options -Indexes RewriteEngine on RewriteRule ^([a-z0-9]+)$ /?L=users.profile&id=$1 [r=301,nc] so if I enter www.mysite.com/username it works with a redirect to users.profile&id=username now the person with an underscore in the username gets a not found error. www.mysite.com/user_name Naturally, the underscore may or may not be there and there could be multiple ones in any position. Does anyone know if this can be fixed? Quote Link to comment https://forums.phpfreaks.com/topic/149457-solved-underscore-messes-up-redirect/ Share on other sites More sharing options...
corbin Posted March 15, 2009 Share Posted March 15, 2009 RewriteRule ^([a-z0-9]+)$ /?L=users.profile&id=$1 [r=301,nc] Change to: RewriteRule ^([a-z0-9_]+)$ /?L=users.profile&id=$1 [r=301,nc] Your pattern says 1 a string starting with and ending with 1 or more letters or numbers. Why would it work with an underscore? Quote Link to comment https://forums.phpfreaks.com/topic/149457-solved-underscore-messes-up-redirect/#findComment-785042 Share on other sites More sharing options...
Daniel0 Posted March 15, 2009 Share Posted March 15, 2009 You might want to also modify your registration script to enforce that usernames will match the same regex you are using in your rewrite. Quote Link to comment https://forums.phpfreaks.com/topic/149457-solved-underscore-messes-up-redirect/#findComment-785304 Share on other sites More sharing options...
backyard Posted March 16, 2009 Author Share Posted March 16, 2009 Thanks that solved my problem. I knew it was missing I just didn't know where to add the underscore to me expression. Quote Link to comment https://forums.phpfreaks.com/topic/149457-solved-underscore-messes-up-redirect/#findComment-785857 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.