【问题标题】:how can I enable mod_rewrite on iis server如何在 iis 服务器上启用 mod_rewrite
【发布时间】:2012-11-28 16:22:05
【问题描述】:

我发现我的服务器上没有启用 mod_rewrite 功能(_SERVER["SERVER_SOFTWARE"] -Microsoft-IIS/7.0),架构 x86 。如何启用 mod_rewrite。谁能帮帮我。

【问题讨论】:

  • 是否在php.ini文件中启用?
  • 我是否在我的服务器上编辑了 php.ini 文件?
  • 你的架构是什么? Linux 还是 Windows?哪个网络服务器?
  • 大胖子提醒正在阅读本文的每个人:不是总是说这是在 IIS 上,而不是在 Apache 上。关于 Apache 的答案在当时是正确的。

标签: php iis iis-7 url-rewriting


【解决方案1】:

对我有用的答案是安装 Microsoft URL Rewrite 模块,然后在站点的根目录中创建一个 web.config 文件,其中包含它(规则):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Security Rule" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions logicalGrouping="MatchAny">
            <add input="{QUERY_STRING}" pattern="mosConfig_[a-zA-Z_]{1,21}(=|\%3D)" ignoreCase="false" />
            <add input="{QUERY_STRING}" pattern="base64_encode.*\(.*\)" ignoreCase="false" />
            <add input="{QUERY_STRING}" pattern="(\&lt;|%3C).*script.*(\>|%3E)" />
            <add input="{QUERY_STRING}" pattern="GLOBALS(=|\[|\%[0-9A-Z]{0,2})" ignoreCase="false" />
            <add input="{QUERY_STRING}" pattern="_REQUEST(=|\[|\%[0-9A-Z]{0,2})" ignoreCase="false" />
          </conditions>
          <action type="CustomResponse" url="index.php" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
        </rule>
        <rule name="SEO Rule">
          <match url="(.*)" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" pattern="" ignoreCase="false" />
            <add input="{URL}" negate="true" pattern="^/index.php" ignoreCase="false" />
            <add input="{URL}" pattern="(/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$" />
          </conditions>
          <action type="Rewrite" url="index.php" />
        </rule>
      </rules>
    </rewrite>
 </system.webServer>
</configuration>

【讨论】:

    【解决方案2】:

    如果您在商业托管服务提供商处进行托管,他们很可能会安装 Microsoft URL Rewrite 模块。这为您提供了与 Apache mod_rewrite 模块类似的功能。

    要测试是否安装了此模块,请在您网站的根目录中创建一个名为web.config 的文件,其中包含以下内容,然后尝试使用http://www.domain.com/google,其中domain.com 是您网站的域。如果您被重定向到 google.com,则您的主机安装了 URL 重写模块。

    web.config:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <clear />
                    <rule name="Redirect to google.com" stopProcessing="true">
                        <match url="^google$" />
                        <action type="Redirect" url="http://www.google.com/" appendQueryString="false" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    

    【讨论】:

      【解决方案3】:

      1) 找到 httpd.conf (通常这个文件可以在名为 conf 、 config 的文件夹中找到)

      2) 找到并取消注释 LoadModule rewrite_module modules/mod_rewrite.so 行

      3) 找到 DocumentRoot “C:/path/to/my/root” 所在的行,你会发现类似的内容

      确保这两个大括号内的内容看起来像

      全部选项

      允许全部覆盖

      4) 现在一切都完成了,重新启动 Apache 服务器,一切顺利

      【讨论】:

      • 在 Windows 上,apache 模块会有一个 .dll 后缀,在 Linux 上你可以在 /etc/httpd//etc/apache2 中找到配置
      【解决方案4】:

      没有适用于 Windows 操作系统的免费版 mod_rewrite for LINUX。我发现的唯一方法是使用 URL REWRITE 在 IIS 上导入 .htaccess 文件,该 URL 在 Web 平台安装程序上免费提供。

      安装 URL REWRITE 组件后,按照以下链接中的步骤导入 .htaccess 文件并创建其 windows 等效文件 web.config 文件。

      http://www.iis.net/learn/extensions/url-rewrite-module/importing-apache-modrewrite-rules

      干杯。

      【讨论】:

        猜你喜欢
        • 2016-01-16
        • 2011-11-12
        • 1970-01-01
        • 1970-01-01
        • 2021-06-04
        • 2014-07-23
        • 1970-01-01
        • 1970-01-01
        • 2011-01-06
        相关资源
        最近更新 更多