我的应用程序中有以下url类型:
http://192.168.0.191/myapp/public/controller_name/action_name
http://192.168.0.191/myapp/public/controller_name/action_name/param1/param2
http://192.168.0.191/myapp/public/controller_name/action_name?parameterlist
Ans我使用以下REGEX进行重定向:
我有以下Regex用于重定向(一切都通过索引页面):
"^([a-zA-Z0-9\/\-_]+)\.?([a-zA-Z]+)?$"
重定向到"/myapp/public/index.php?url=$1&extension=$2")
以下是使用的网址示例:
http://192.168.0.191/myapp/public/customers -> Call customer controller
http://192.168.0.191/myapp/public/customers/detail/2 -> Show customer detail for id = 2
两者都很好。我的问题是下面的URL - 加载Datagrid对象的客户数据:
http://192.168.0.191/myapp/public/customer/loadDtData?draw=1&columns%5B0%5D%5Bdata%5D=0&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=1&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=2&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=true&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B3%5D%5Bdata%5D=3&columns%5B3%5D%5Bname%5D=&columns%5B3%5D%5Bsearchable%5D=true&columns%5B3%5D%5Borderable%5D=true&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B4%5D%5Bdata%5D=4&columns%5B4%5D%5Bname%5D=&columns%5B4%5D%5Bsearchable%5D=true&columns%5B4%5D%5Borderable%5D=true&columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=desc&start=0&length=25&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1450111563514
如何修复Regex以在最后/
之后但?
之前分隔文本,然后在?
之后将文本作为参数传递给应用程序。
感谢您的帮助。我使用lighttpd作为Web服务器。
OBS:对于Apache,我会使用下面的RewriteRule
来解决问题,但是lighttpd不支持QSA:
RewriteRule ^([a-zA-Z0-9\/\-_]+)\.?([a-zA-Z]+)?$ index.php?url=$1&extension=$2 [QSA,L]
答案 0 :(得分:1)
如果没有QSA
标志,请尝试以下规则:
url.rewrite = ( "^/([\w/-]+)\.?([a-zA-Z]+)?(?:\?(.*))?" => "/index.php?url=$1&extension=$2&$3" )