PHP Mod rewrite for user accounts

我的未来我决定 提交于 2019-12-11 19:00:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!