问题
So I've been searching for how I can rewrite a url that is like this:
http://www.example.com/profile.php?username=test
to something like this:
http://www.example.com/user/test
Also, I would like to rewrite other urls that are like this:
(feed page) 'url'/profile.php?username=test&page=feed (videos page) 'url'/profile.php?username=test&page=videos
to something like this:
(feed page) 'url'/user/test/feed (videos page) 'url'/user/test/videos
I read up on this and couldn't really find anything to my liking. I really don't understand mod_rewrite that well and would be thrilled if someone could explain it to me using the examples above. Thanks!
回答1:
Here is the code for your .htaccess file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^user/([^\/]*)/([^\/]*)$ profile.php?username=$1&page=$2 [NC,L]
来源:https://stackoverflow.com/questions/17386622/php-mod-rewrite-for-user-accounts