简体   繁体   中英

HTACCESS code not working for vanity URLS

Right now, the following URLs are displayed:

www.mysite.com/account.php?username=$username

What I want is:

www.mysite.com/$username

I'm using the following code in my htaccess file:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.+)$ /account.php?username=$1 [L,QSA]

But it doesn't work: URLs are the same as before.

What's wrong ?

Your rule does only this:

If someone requests www.mysite.com/$username , internally server the resource at /account.php?username=$username .

That's all. The syntax being RewriteRule <the URI that matches this> <gets internally rewritten to this>

So you have nothing that does anything about changing the URL. That's not how mod_rewrite works. What it sounds like you want is to be able to externally redirect the browser so that what's in the location bar changes. To do that, it's a lot more complicated:

RewriteCond %{THE_REQUEST} \ /account\.php\?username=([^&\ ]+)&?([^\ ]*)
RewriteRule ^ /%1?%2 [L,R=301]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM