I have the following code in my .htaccess.
RewriteEngine On
RewriteRule ^/(\w+)/?$ /?user=$1
I’m trying to rewrite
http://domain.com/?user=username into http://domain.com/username. Unfortunately this code doesn’t rewrite anything. Please help
Note:
I checked phpinfo() and mod_rewrite is loaded.
Update
I need to get username from url like http://facebook.com/username. But this code rewrites every folder in root folder, so my /css folder become http://domain.com/css/?u=common. How to allow this code works only for http://domain.com/index.php
The mistake you are doing is the use of
/in the beginning of the line^/(\w+)/?$rewrite rules strips off the
/from the beginning of the pattern to be matched in.htaccessand directory context.Try doing this:
From RewriteRule Directive docs :
Edit: Answer updated as per OP’s request:
Add this :