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

发布于 2024-09-15 17:03:35 字数 820 浏览 4 评论 0原文

我正在 IIS7 中使用 URL 重写模块并使用用户友好 URL 规则模板。

我正在尝试获取如下 URL:

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

重写为

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

使用模板,它会自动生成类似以下内容:

^SomethingEnd\.aspx$

重定向到

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

以及反向为

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

be

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

我的问题是,如何使其动态化?虽然我的查询字符串中的参数数量有限,但我真的不想这样做,例如,如果我有 6 个参数,则有 6 个单独的重写规则(并且应用相反的规则)。

我尝试过

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

,但这似乎不起作用。

任何帮助将不胜感激。

谢谢你!

I'm using URL Rewrite module in IIS7 and using the User Friendly URL Rule template.

I'm trying to get URLs like:

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

to rewrite to

SomethingEnd.aspx?param1=something¶m2=something¶m3=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).

I tried

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

but that doesn't seem to work.

Any help would be greatly appreciated.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦醒灬来后我 2024-09-22 17:03:35

您可以使用split


编辑

举个例子,在 javascript 中,你可以使用这个:

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

这会返回一个数组:

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

因此,你只需要一个循环来获取正确的信息。

You can use split.


EDIT

Just as an example, in javascript, you can use this:

"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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文