Rewrite rule index.php?/controller/method/param to /controller/method/param

拜拜、爱过 提交于 2019-12-12 04:44:48

问题


I need a rewrite rule for this url

http://localhost/~user/frame/lib/index.php?/controller/method/12/22/

How can i rewrite it that i can call it like this

http://localhost/~user/frame/lib/controller/method/12/22/

What is the rewrite rule for the above problem? I hope i could explain my question clear.


回答1:


Try this rule:

RewriteRule $2 !^index\.php$
RewriteRule ^(/~[^/]+/[^/]+/[^/]+)(/.*)? $1/index.php?$2

Depending on where you want to use this rule (my suggestion is meant for the server/virtual host configuration), you may need to remove the contextual path prefix from the pattern. So if you want to use the rule in the .htaccess file in /~user/:

RewriteRule $2 !^index\.php$
RewriteRule ^([^/]+/[^/]+)(/.*)? $1/index.php?$2

Or if in /~user/frame/lib/:

RewriteRule $0 !^index\.php$
RewriteRule .* index.php?/$0



回答2:


RewriteRule ^(.*)lib/(.*)$ / $1lib/index.php?/$2

That's the simplest way, but not the most robust as it might screw with other URLs. So it's worth checking thoroughly, or posting your entire .htaccess file.



来源:https://stackoverflow.com/questions/2806242/rewrite-rule-index-php-controller-method-param-to-controller-method-param

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