英文:
IIS Rewritemap to ignore all querystrings
问题
We have made a new site for a customer. He had an old site, and we importerd the old sitemap to a rewritemap file for IIS.
The problem is, they seem to use a lot of querystrings in the old URLS.
So /projects/project1?page=2
for example. The new site doesn't use these querystrings.
Is there a way to just ignore all querystrings for the redirectmap?
I want to redirect if the source-without-querystring exists in the rewritemap.
So if the input is /projects/project1?page=2
, I want it to find /projects/project1/
in my rewritemap.
The rules are as follows:
<rewrite>
<rewriteMaps configSource="rewritemaps.config"></rewriteMaps>
<rules>
<rule name="Redirect rule1 for Redirects">
<match url="(.*[^/])" />
<conditions>
<add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
英文:
We have made a new site for a customer. He had an old site, and we importerd the old sitemap to a rewritemap file for IIS.
The problem is, they seem to use a lot of querystrings in the old URLS.
So /projects/project1?page=2
for example. The new site doesn't use these querystrings.
Is there a way to just ignore all querystrings for the redirectmap?
I want to redirect if the source-without-querystring exists in the rewritemap.
So if the input is /projects/project1?page=2
, I want it to find /projects/project1/
in my rewritemap.
The rules are as follows:
<rewrite>
<rewriteMaps configSource="rewritemaps.config"></rewriteMaps>
<rules>
<rule name="Redirect rule1 for Redirects">
<match url="(.*[^/])" />
<conditions>
<add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
答案1
得分: 1
根据您的描述,我理解您不想在匹配中包含查询字符串,请纠正我是否理解错误。
您规则中的{Redirects:{REQUEST_URI}}条件检查是否有一个与REQUEST_URI服务器变量匹配的重写映射键。请注意,该变量包含查询字符串:
{REQUEST_URI} = /projects/project1?page=2
如果您不想在匹配中包含查询字符串,请改用{PATH_INFO}服务器变量,如下所示:
{PATH_INFO} = /projects/project1
英文:
Based on your description, what I understand is that you don't want to include the query string in the match, please correct me if I understand wrong.
The {Redirects:{REQUEST_URI}} condition in your rule checks whether there is a key in this rewrite map matching the REQUEST_URI server variable. Note that this variable contains the query string:
{REQUEST_URI} = /projects/project1?page=2
If you don't want to include the query string in the match, use the {PATH_INFO} server variable instead of {REQUEST_URI}.
{PATH_INFO} = /projects/project1
<rewrite>
<rewriteMaps configSource="rewritemaps.config"></rewriteMaps>
<rules>
<rule name="Redirect rule1 for Redirects">
<match url="(.*[^/])" />
<conditions>
<add input="{Redirects:{PATH_INFO}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论