Jump to content

[SOLVED] Underscore messes up redirect


backyard

Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/149457-solved-underscore-messes-up-redirect/
Share on other sites

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.