【发布时间】:2018-01-23 22:37:31
【问题描述】:
我正在使用 IIS 8,只是学习重写,因为我从未写过任何关心 SEO 的东西。
假设 url 如下所示,我有以下规则有效:/survey/abc123/email
<rule name="Survey Rule" stopProcessing="true">
<match url="survey/([_0-9a-z-]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="survey.htm?var1={R:1}&var2={R:2}" />
</rule>
在survey.htm 页面上,我有检查var1 和var2 是否存在的代码,但是在此重写中,如果我有url /survey/abc123,它显然没有达到调查规则。我尝试了几个<conditions>,但都能找到合适的。
我觉得一定有办法说
If {R:1} exists then var1={R:1} else var1=''
If {R:2} exists then var2={R:2} else var1=''
理想情况下是某种类型的 if 循环。无论调查后有多少/,无论是 0 还是 10,它都将始终是调查页面,是否有任何方法可以重写?
我查看了重写图,但不确定是否能解决此问题。
编辑
我想重写的可能网址:
/survey/abc123/
/survey.htm?var1=abc123
/survey/abc123/email/
/survey.htm?var1=abc123&var2=email
/survey/abc123/email/bob/
/survey.htm?var1=abc123&var2=email&var3=bob
/survey/abc123/email/bob/someOtherVar
/survey.htm?var1=abc123&var2=email&var3=bob&var4=someOtherVar
/result/1/
/result.htm?var1=1
/result/1/test@example.com
/result.htm?var1=1&var2=test@example.com
我希望斜杠后的第一项成为页面名称,然后将每个项目变成“query_string”。我希望这更有意义。
【问题讨论】:
-
如果你能添加 3-5 个示例 URL 以及它应该如何重写它会很棒。那我就可以帮你改写规则了
-
@VictorLeontyev 我尝试添加一些示例,希望对您有所帮助。
标签: mod-rewrite iis url-rewriting web-config