I’m trying to rewrite this url:
http://www.example.com/user.php?user=username
into
http://example.com/username
I’m using this code in my .htaccess:
RewriteEngine On
RewriteRule ^([^/]*)$ /user.php?user=$1 [L]
but its giving me an internal error. Is there something wrong?
To match the query string part of a URL, you have to use RewriteCond, like this:
So the RewriteCond rule matches the username in ?user=name and then the %1 uses that value in the resulting rewrite on the last line of my example.
On the slash issue, URLs like /name get automatically redirected to URLs like /name/ if the web server finds that /name is a directory. So if your intention is to map user.php/user=name to something like /name/index.html, you will cause that slash to get inserted. But if your intention is to map it to a file (or CGI script) at /name then it will work as expected.