首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Question2Answer mod_rewrite的IIS重写等效项

Question2Answer mod_rewrite的IIS重写等效项
EN

Stack Overflow用户
提问于 2013-06-11 21:09:48
回答 1查看 706关注 0票数 1

web.config中的哪个IIS URL重写规则集与Question2Answer的默认.htaccess中提供的此mod_rewrite规则集等效?

代码语言:javascript
复制
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>

该规则与典型的WordPress风格重写的不同之处在于需要传递嵌套的路径元素。以下是将Question2Answer部署到服务器上的qa目录时,Question2Answer用于验证重写是否正常工作的测试URL的示例(部署到web根目录的过程类似地失败):

代码语言:javascript
复制
http://localhost:32568/qa/url/test/%24%26-_~%23%25%5C%40%5E%2A%28%29%3D%21%28%29%5D%5B%60%27%3B%3A%7C%22.%7B%7D%2C%3C%3E%3F%23+%CF%80%C2%A7%C2%BD%D0%96%D7%A9?dummy=&param=%24%26-_%7E%23%25%5C%40%5E%2A%28%29%3D%21%28%29%5D%5B%60%27%3B%3A%7C%22.%7B%7D%2C%3C%3E%3F%23+%CF%80%C2%A7%C2%BD%D0%96%D7%A9

这是IIS管理器的“导入mod_rewrite规则”功能提出的:

代码语言:javascript
复制
<rewrite>
   <rules>
      <rule name="Imported Rule 1" stopProcessing="true">
      <match url="." ignoreCase="false" />
      <conditions>
         <add input="{URL}" pattern="^(.*)//(.*)$" ignoreCase="false" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="{C:1}/{C:2}" />
      </rule>
      <rule name="Imported Rule 2" stopProcessing="true">
      <match url="^.*$" ignoreCase="false" />
      <conditions>
         <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Redirect" url="index.php?qa-rewrite={R:0}&amp;{QUERY_STRING}" appendQueryString="false" />
      </rule>
   </rules>
</rewrite>

我还添加了以下内容,以便测试URL将以与实际导航URL相同的方式失败:

代码语言:javascript
复制
<security>
   <requestFiltering allowDoubleEscaping="true" />
</security>

question2answer QA的网站上没有question covering this的答案。希望在IIS URL重写方面有经验的人会知道。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-12 22:05:49

此配置有效:

代码语言:javascript
复制
<?xml version="1.0"?>
<configuration>
  <system.webServer>

    <rewrite>
      <rules>
        <rule name="DeduplicateSlashes" stopProcessing="true">
          <match url="." ignoreCase="false" />
          <conditions>
            <add input="{URL}" pattern="^(.*)//(.*)$" ignoreCase="false" />
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="{C:1}/{C:2}" />
        </rule>
        <rule name="CleanRouting" stopProcessing="true">
          <match url="^.*$" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php?qa-rewrite={R:0}&amp;{QUERY_STRING}" appendQueryString="false" />
        </rule>
      </rules>
    </rewrite>

    <!-- Double escaping is needed for URLs with '+', e.g. for the account page for a username with a space. -->
    <security>
       <requestFiltering allowDoubleEscaping="true" />
    </security>

  </system.webServer>
</configuration>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17044938

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档