mod_rewrite: multi-level URL using a request parameter

别说谁变了你拦得住时间么 提交于 2019-12-11 12:13:57

问题


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

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.

users/admin/activity

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

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?


回答1:


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]

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



来源:https://stackoverflow.com/questions/11179054/mod-rewrite-multi-level-url-using-a-request-parameter

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