How do I make URL's like www.mysite.com/user/USERNAME? I have a usersystem and instead of doing www.mysite.com/users.php?user=USERNAME, I want the folder type URLs.

How do I make URL's like www.mysite.com/user/USERNAME? I have a usersystem and instead of doing www.mysite.com/users.php?user=USERNAME, I want the folder type URLs.
I always get myself muddled up with HTACCESS for some reason
But something like this should work, I don't have access to our server atm though, so I cannot test it out.
PHP Code:RewriteEngine On
RewriteRule ^user/([a-zA-Z0-9=_.!-]+)/$ users.php?user=$1 [NC]
This should help: http://www.habboxforum.com/showthread.php?t=514476
This should work, just modified the code that Source posted:
EDIT: Looks like Jack bet me to it!Code:RewriteEngine on RewriteRule ^user/([A-Za-z0-9-]+)/?$ users.php?user=$1 [L]
I could see why you would add the last rule flag but on Jacks he uses the case insensitive flag when he's defining both lower and upper case letters.. Just doing extra work, mine was.
I'm sure you could also do something like.Code:RewriteRule ^user/([^/]+)/?$ users.php?user=$1
Code:RewriteRule ^user/(.+?)/?$ users.php?user=$1
The easiest way to do it is with custom routes for each url type (as shown above).
The other option is to redirect everything to index.php (or a php file to handle it) and then use php to handle it; this option, however, is only normally used with frameworks.
It wouldn't be a plus though would it? I thought it was (.*?) for non greedy matches?I could see why you would add the last rule flag but on Jacks he uses the case insensitive flag when he's defining both lower and upper case letters.. Just doing extra work, mine was.
I'm sure you could also do something like.Code:RewriteRule ^user/([^/]+)/?$ users.php?user=$1
Code:RewriteRule ^user/(.+?)/?$ users.php?user=$1
They're both non-greedy, the difference is .* matches zero or more where as .+ matches one or more.
Want to hide these adverts? Register an account for free!