mod_rewrite的:使用一个请求参数多层次的网址多层次、参数、网址、mod_rewrite

2023-09-02 00:58:48 作者:那一年的蜕变

目前,我有这样的设置和用户文件夹内的精细工作。

I currently have this set up and working fine inside a users folder.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?i=$1

如127.0.0.1/site/users/admin去127.0.0.1/site/users/index.php?i=admin~~V

e.g 127.0.0.1/site/users/admin goes to 127.0.0.1/site/users/index.php?i=admin

现在,因为这是一个个人资料页面,如何将我做一些像这样的。

Now as this is for a profile page, how would i do something such as this.

用户/管理员/活动

因此​​,它会显示该用户的活动页面?我对我怎么会去这完全糊涂了。

So that it would show the activity page for that user? I am totally confused on how i would go about this.

这将是最好使的index.php接受页面$ _ GET变量?但是,如何将我得到的htaccess来解决呢?

Would it be best to make the index.php accept a page $_GET variable? But the how would i get htaccess to work around it?

推荐答案

您的规则将是这个样子:

You rules will look something like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(.*)$ index.php?i=$1&page=$2  [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?i=$1  [L]

现在你的index.php应该得到2 $ _ GET 变量,

Now your index.php should be getting 2 $_GET variables, i and page.