【问题标题】:Redirect is not working properly in iis重定向在 iis 中无法正常工作
【发布时间】:2011-12-22 13:40:31
【问题描述】:

我遇到了类似于 this post 的问题

我试过了

RewriteCond %{HTTP_HOST} ^myApplication.com
RewriteCond %{REQUEST_URI} !myApplication/
RewriteRule ^(.*)$ myApplication/$1 [L]

RewriteCond %{HTTP_HOST} www.myApplication.com
RewriteCond %{REQUEST_URI} !myApplication/
RewriteRule ^(.*)$ myApplication/$1 [L]

但问题是 url 仅适用于 www.myApplication.com/myApplication 但我想隐藏 myApplication subfolder 。 我将非常感谢您对此的任何帮助。

更新: 我试过这个,它给出了 500 服务器错误。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="mod_rewrite" path="*" verb="*" modules="IsapiModule" scriptProcessor="path to scriptproc" resourceType="Unspecified" requireAccess="None" preCondition="bitness32" />
        </handlers>
        <rule name="Rewrite to myApplicaton" stopProcessing="true">
         <match url="(.*)" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^(www\.)myApplication\.com$" />
                <add input="{REQUEST_URI}" pattern="^myApplication/" negate="true" />
            </conditions>
        <action type="Rewrite" url="/myApplication/{R:0}" />
        </rule>
    </system.webServer>
</configuration>

【问题讨论】:

  • 这些是 Apache 重写规则。它们在 IIS 中不起作用
  • 对 apache 是否正确?任何 web.config 规则都适用于相同的工作?任何建议如何做到这一点。谢谢。

标签: .htaccess iis redirect


【解决方案1】:

以下应该做你想要的:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Rewrite to myApplicaton" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^(www\.)myApplication\.com$" />
                        <add input="{REQUEST_URI}" pattern="^myApplication/" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/myApplication/{R:0}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

【讨论】:

  • 感谢 Marco,您回答了这个问题,但没有奏效。出现 500 错误。我不知道如何解决。我已经用我尝试过的方法更新了问题。如果你能做点什么,请帮忙。谢谢。
  • 您发布的 web.config 中的 XML 无效。我已经更新了我的帖子以包含您需要作为开始使用的完整 XML。从上面用我的完全替换你的 web.config。 Mod_rewrite 是 Apache 重写模块的名称。 IIS 的模块称为 URLRewrite。如果您还没有安装它,您可以从here 下载它。您不需要激活它或 web.config 中的任何内容,只需将重写规则添加到 web.config 将激活 URLRewrite 模块。
猜你喜欢
  • 2015-08-12
  • 1970-01-01
  • 2017-09-23
  • 2015-08-09
  • 2014-07-01
  • 2015-12-21
  • 2017-03-04
相关资源
最近更新 更多