htaccess mod_rewrite have links  domain.com/bobsmith

Azurewave
Azurewave used Ask the Experts™
on
Hey there, I would like to edit my htaccess to allow links like this and reroute them where I want them.

domain.com/bobsmith

would go to

domain.com/index.php?user=bobsmith

the only acceptable chars in bobsmith are

a-z 0-9 and - _

I have something right now, but it only works if I have a / at the end, looking for something where I don't need the "/" at the end.

I am running an Apache server.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2008
Commented:
> I have something right now, but it only works if I have a / at the end,

You'd have to adjust your regEx a little bit:

RewriteEngine on
RewriteRule ^([a-z0-9-]+)$ /index.php?user=$1 [L]

or, if you'd like to match the trailing slash as well:

RewriteRule ^([a-z0-9-]+)/?$ /index.php?user=$1 [L]

Author

Commented:
This works, to add underscores as well

([a-z0-9-_]+)

i would do that yes?

that supports both dashes and underscores?

Author

Commented:
hmm, if I do ([a-z0-9-_]+), it ends up breaking, and says internal server error any ideas?
Top Expert 2008

Commented:
Change the position of -_ into _- or escape the hyphen; \-_

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial