apache url rewrite problem

雨燕双飞 提交于 2019-12-13 03:36:45

问题


is it possible to rewrite the following URL:

http://dev.aurora.com/problem/getproblems/fieldset/2?search=false&rows=20&page=1

to

http://dev.aurora.com/problem/getproblems/fieldset/2/search/false/rows/20/page/1

Thanx in advance


回答1:


Try these rules in the .htaccess file in your document root directory:

RewriteRule ^problem/getproblems/fieldset/2/([^/]+)/([^/]+)/(.+)$ /problem/getproblems/fieldset/2/$3?$1=$2 [N,QSA]
RewriteRule ^problem/getproblems/fieldset/2/([^/]+)/([^/]+)$ problem/getproblems/fieldset/2?$1=$2 [L,QSA]

The first rule is for the recursion and the second rule ends the recursion.




回答2:


Certainly; something like

^(.*)\?(search)=(.+)&(rows)=(.+)&(page)=(.+)$ $1/$2/$3/$4/$5/$6/$7

will work, but no matter whose answer you follow, you'll always need to tweak it to your situation, so you need to understand how it works.

http://httpd.apache.org/docs/2.2/rewrite/rewrite_intro.html#regex, http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html and something like http://civilolydnad.se/projects/rewriterule/ will get you a long way.



来源:https://stackoverflow.com/questions/3430488/apache-url-rewrite-problem

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