Reputation: 4323
I am trying to make a friendly looking URLs for my ugly URLs.
mod
directory contains an index.php
and a user.php
file. The index.php
only has some links, of various formats, to the user page.
path to mod
directory like this : http://localhost/mod/
at this time user's urls something like this..
http://localhost/mod/user.php?id=Ricky etc..
I need to make that ugly one to nice looking one something like this..
http://localhost/mod/user/Ricky
I tried it in my htaccess file, and this is code so far in that file.
# Enable Rewriting
RewriteEngine on
# Rewrite user URLs
# Input: user/NAME/
# Output: user.php?id=NAME
RewriteRule ^user/([a-z]+)/?$ user.php?id=$1
This is not working for me. Hope someone will help me. Thank you.
Upvotes: 1
Views: 196
Reputation: 18833
RewriteRule ^user/([A-Za-z]+)/?$ user.php?id=$1 [NC,L]
State end of line and case insensitive with [NC,L]
You can also just use \w to match all text chars (non digit)
RewriteRule ^user/(\w+)/?$ user.php?id=$1 [NC,L]
Here's a cheat sheet for regex: http://www.regular-expressions.info/reference.html
Upvotes: 1