简体   繁体   中英

mod_rewrite url with $_GET parameter

I honestly can't see where I'm going wrong with mod_rewrite. I'm wanting to build a basic social network, but I want the user profile URLs to look like subdomains, like "www.mysite.com/user/fred" and not "www.mysite.com/user?u=fred". My .htaccess page looks like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L,QSA]
RewriteRule    ^user/([A-Za-z]+)/(0-9]+)/?    user?u=$1     [L,QSA]

But navigating to www.mysite.com/user/fred gives me a 404 error. I've tried a few different ones from different tutorial websites and stackoverflow questions, but none of them will work. I know that mod_rewrite is definitely installed on my server, because I checked the php_info() and the rewrite rule for normal URLs work fine ("www.mysite.com/browse" instead of "www.mysite.com/browse.php").

Try replacing your 3rd and 4th line for:

RewriteRule ^user/(.*) user.php?u=$1 [QSA]
RewriteRule ^([^\.]+)$ $1.php [NC,L]

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