简体   繁体   English

使用IIS7的URL重写模块的正则表达式问题

[英]Regex question using IIS7's URL Rewrite module

I'm using URL Rewrite module in IIS7 and using the User Friendly URL Rule template. 我正在IIS7中使用“ URL重写”模块,并使用了“用户友好的URL规则”模板。

I'm trying to get URLs like: 我正在尝试获取如下网址:

Something/param1/something/param2/something/param3/something/something2/ etc.etc.

to rewrite to 重写为

SomethingEnd.aspx?param1=something&param2=something&param3=something/something2& etc.etc.

Using the templates, it automatically generates something like: 使用模板,它会自动生成如下内容:

^SomethingEnd\.aspx$

to redirect to 重定向到

Something/{C:1}/{C:2}/{C:3}/{C:4}/{C:5}/{C:6} etc.

and the reverse to be 而相反的是

^Something/([^/]+)/([^/]+)/?$

to be 成为

SomethingEnd.aspx?{R:1}={R:2}

My problem is, how can I make it dynamic? 我的问题是,如何使它动态? Though there is a finite amount of params I have in my query string, I really don't want to make, for example, if I have 6 params, 6 separate rewrite rules (and the reverse applied). 尽管我的查询字符串中包含有限数量的参数,但是,例如,如果我有6个参数,6个单独的重写规则(并应用了反向),我真的不想创建。

I tried 我试过了

^Something/([^/]+)*/?$

but that doesn't seem to work. 但这似乎不起作用。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Thank you! 谢谢!

You can use split . 您可以使用split


EDIT 编辑

Just as an example, in javascript, you can use this: 仅作为示例,在javascript中,您可以使用以下代码:

"Something/param1/something/param2/something/param3/something/something2/".split(/([^/]+)\/([^/]+)/)

And this returns an array: 这将返回一个数组:

["", "Something", "param1", "/", "something", "param2", "/", "something", "param3", "/", "something", "something2", "/"]

So, you need just a loop to get correct information. 因此,您只需要循环就可以获取正确的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM