IIS Rewritemap用于忽略所有查询字符串。

huangapple go评论53阅读模式
英文:

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:

&lt;rewrite&gt;
  &lt;rewriteMaps configSource=&quot;rewritemaps.config&quot;&gt;&lt;/rewriteMaps&gt;
  &lt;rules&gt;
    &lt;rule name=&quot;Redirect rule1 for Redirects&quot;&gt;
      &lt;match url=&quot;(.*[^/])&quot; /&gt;
      &lt;conditions&gt;
        &lt;add input=&quot;{Redirects:{REQUEST_URI}}&quot; pattern=&quot;(.+)&quot; /&gt;
      &lt;/conditions&gt;
      &lt;action type=&quot;Redirect&quot; url=&quot;{C:1}&quot; appendQueryString=&quot;false&quot; redirectType=&quot;Permanent&quot; /&gt;
    &lt;/rule&gt;
  &lt;/rules&gt;
&lt;/rewrite&gt;

答案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

&lt;rewrite&gt;
      &lt;rewriteMaps configSource=&quot;rewritemaps.config&quot;&gt;&lt;/rewriteMaps&gt;
      &lt;rules&gt;
        &lt;rule name=&quot;Redirect rule1 for Redirects&quot;&gt;
          &lt;match url=&quot;(.*[^/])&quot; /&gt;
          &lt;conditions&gt;
            &lt;add input=&quot;{Redirects:{PATH_INFO}}&quot; pattern=&quot;(.+)&quot; /&gt;
          &lt;/conditions&gt;
          &lt;action type=&quot;Redirect&quot; url=&quot;{C:1}&quot; appendQueryString=&quot;false&quot; redirectType=&quot;Permanent&quot; /&gt;
        &lt;/rule&gt;
      &lt;/rules&gt;
    &lt;/rewrite&gt;

huangapple
  • 本文由 发表于 2023年5月22日 15:34:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76303914.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定