PHPmod-rewrite用户帐户帐户、用户、PHPmod、rewrite

2023-09-02 20:37:55 作者:愿我成为自己的太阳

所以,我一直在寻找我怎么可以重写URL是这样的:

So I've been searching for how I can rewrite a url that is like this:

http://www.example.com/profile.php?username=test

要这样的:

http://www.example.com/user/test

另外,我想重写其他的网址是这样的:

Also, I would like to rewrite other urls that are like this:

(喂页)URL/ profile.php用户名=测试&放大器;页=饲料 (视频页)URL/ profile.php用户名=测试&放大器;页面=视频

(feed page) 'url'/profile.php?username=test&page=feed (videos page) 'url'/profile.php?username=test&page=videos

要这样的:

(喂页)URL/用户/测试/饲料 (视频页)URL/用户/测试/视频

(feed page) 'url'/user/test/feed (videos page) 'url'/user/test/videos

我读了这一点,并不能真正找到任何我喜欢的。我真不明白的mod_rewrite的很好,会很激动,如果有人可以用上面的例子解释给我听。谢谢!

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!

推荐答案

下面是$ C $下.htaccess文件。

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]