标签: url-rewrite-module

ASP.NET OAuth存在URL重写问题

我的生产设置如下:

  • M1 - ASP.NET网站
  • M2 - IIS URL重写2.0 + ARR 3.0

使用IIS URL Rewrite,对M2的任何请求,例如http:// m2 /app/login.aspx将被重定向到M1,如http:// m1 /app/login.aspx.

在M1上,ASP.NET Open Auth已在网站上实施,以使用Google外部身份验证.当用户点击Google按钮时,浏览器将被重定向到Google登录页面以允许用户进行身份验证.

但是当从M2访问网站时,.net oAuth(https:// accounts.google.com/[query-string])生成的重定向网址将重定向到Google,正在被URL重写替换为http:// m2/[query-string].

所以要清楚; 当通过外部身份验证提供程序进行身份验证请求时,返回302重定向.通常这种形式可能如下所示:

响应标题:

...

位置:https:// accounts.google.com/o/oauth2/auth?big_long_query_string

...

此重定向由位于代理服务器后面的服务器(M1)创建(M2 - IIS URL Rewrite 2.0 + ARR 3.0).因此,重写服务器将Location标头重写为:

响应标题:

...

位置:http:// M1/o/oauth2/auth?big_long_query_string

...

我们需要的是一条规则,它不会在重定向时重写位置URL.它也只能针对某些重定向.大多数情况下,这里提到的行为是必需的,因为所有重定向都被重定向到主代理服务器.有人可以为某些重定向建议解决方案或解决方法吗?

asp.net oauth url-rewrite-module arr

14
推荐指数
1
解决办法
1540
查看次数

如何排除IIS URL重写的目录?

我有一个domain.com/index.php和一个友好的网址规则来重定向domain.com/index.php?s=?要求.我使用带有URL重写附加组件的IIS webserver.

以上工作正常.但是,对admin目录的请求存在问题...

我还有domain.com/admin/cloud/index.php,有时需要获取或发送数据(通过Ajax).当规则处于活动状态时,数据不可用,当我删除上述规则时,数据可用.

如何使用上面的网址规则并排除域名(或)域名内容中的所有其他请求?

这是我目前的规则集:

<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
    <match url="^index\.php$" />
    <conditions>
        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
        <add input="{QUERY_STRING}" pattern="^s=([^=&amp;]+)$" />
    </conditions>
    <action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
    <match url="^([^/]+)/?$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="index.php?s={R:1}" />
</rule>
Run Code Online (Sandbox Code Playgroud)

我尝试了很多方法,包括路径信息......但没有成功.也许有人可以暗示一下?

谢谢!

iis url iis-7 rewrite url-rewrite-module

13
推荐指数
1
解决办法
2万
查看次数

在IIS7中重写地图 - 如何使匹配选项包含尾部斜杠?

我已经阅读过几个组合的前30个谷歌点击IIS rewrite map condition等等,但我找不到任何体面的文档,无论是在microsoft.com网站还是其他地方.

我在IIS7中有一堆重写映射,我想处理它们,而不管它们是否后跟一个尾部斜杠.所以www.foo.com/bar,www.foo.com/bar/两者都应该符合规则.

<rewrite>
    <rewriteMaps>
        <rewriteMap name="ShortURLs">
            <add key="/terms" value="/en-us/terms-and-conditions/"/>
            <add key="/privacy" value="/en-us/privacy-and-cookies/"/>
            <add key="/buy" value="/en-us/where-to-buy/"/>
        </rewriteMap>
    </rewriteMaps>
    <rules>
        <rule name="Short URL redirects">
            <match url="^/?(.+)/?$" />
            <conditions>
                <add input="{ShortURLs:{REQUEST_URI}}" pattern="(.+)"/>
            </conditions>
            <action type="Redirect" url="{C:1}" appendQueryString="true"/>
        </rule>
    </rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)

现在这非常有效,除了我能找到/terms/匹配重写映射中第一个键的唯一方法是复制映射,使其显示为:

<rewriteMap name="ShortURLs">
    <add key="/terms" value="/en-us/terms-and-conditions/"/>
    <add key="/privacy" value="/en-us/privacy-and-cookies/"/>
    <add key="/buy" value="/en-us/where-to-buy/"/>

    <add key="/terms/" value="/en-us/terms-and-conditions/"/>
    <add key="/privacy/" value="/en-us/privacy-and-cookies/"/>
    <add key="/buy/" value="/en-us/where-to-buy/"/>
</rewriteMap>
Run Code Online (Sandbox Code Playgroud)

考虑到我首先使用正则表达式匹配它们,这看起来非常荒谬.添加/?条件输入或条件模式似乎不起作用.

我已经看到了答案,以IIS7改写地图的正则表达式?提到正则表达式不能使用(引用在URL重写模块中使用重写映射)但是,正如我在那里评论的那样,这似乎与在该文本之前给出的具体示例相关,而不是批发"这可能永远不会起作用" …

regex iis-7 rewritemap url-rewrite-module

12
推荐指数
1
解决办法
3670
查看次数

使用IIS 8.5,URL Rewrite 2.0和ARR 3.0的反向代理下的ASP.NET回发错误

我想在IIS中设置反向代理,但在我的配置中,我遇到了ASP.NET回发的问题.当您单击代理网站的任何提交按钮时,您会收到404错误.浏览器地址栏中的URL更改为重写的URL.

例如,我需要代理的网站是http://website.com/host.这里http://website.comhttp://website.com/host是单独的Web应用程序.主机在website.com下作为虚拟文件夹运行.

我想通过以下URL访问主机:http://me.local/myhost.在IIS中,me.local是一个asp.net Web应用程序,Myhost作为另一个应用程序添加为me.local的子项.只要您不在代理网站上的任何地方点击提交按钮,一切都会正常工作.执行此操作后,您将转到http://me.local/host页面,这会导致404错误.当你查看页面的html源代码时,表单的动作url被正确设置为/ myhost

为什么会发生错误?是否可以在IIS中修复它,还是需要对主机应用程序进行更改?

我的服务器正在运行IIS 8.5.主机服务器是一个旧的IIS 6,Web应用程序可以是asp.net 1.1或asp.net 2.0.

来自"myhost"应用程序的web.config的重写规则部分是:

<configuration>
    <system.webServer>
        <rewrite>
            <rules> 
                <rule name="Route the requests for host" stopProcessing="true"> 
                    <match url="^(.*)" /> 
                    <conditions> 
                        <add input="{CACHE_URL}" pattern="^(https?)://" /> 
                    </conditions> 
                    <action type="Rewrite" url="{C:1}://website.com/host/{R:1}" /> 
                    <serverVariables> 
                        <set name="HTTP_ACCEPT_ENCODING" value="" /> 
                    </serverVariables> 
                </rule>
                <rule name="hostToDefault" stopProcessing="true">
                    <match url="^" />
                    <conditions>
                        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
                    </conditions>
                    <action type="Redirect" url="default.aspx" appendQueryString="false" />
                </rule>
                <rule name="RedirectUserFriendlyURL1" stopProcessing="true">
                    <match url="^(.*)default\.aspx$" />
                    <conditions>
                        <add …
Run Code Online (Sandbox Code Playgroud)

asp.net iis reverse-proxy url-rewriting url-rewrite-module

11
推荐指数
0
解决办法
990
查看次数

IIS上的Host Angular应用程序 - 重定向到root并强制HTTPS

我在IIS中托管了一个角度应用程序.为了将所有请求重定向到应用程序的根目录并允许角度路由处理不同的路由,我添加了一个带有URL Rewrite规则的web.config文件,如下所示:

<configuration>
<system.webServer>
  <rewrite>
    <rules>
     <rule name="Angular Routes" stopProcessing="true">
         <match url=".*" />
       <conditions logicalGrouping="MatchAll">
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
       </conditions>
       <action type="Rewrite" url="/" />
     </rule>
  </rules>
 </rewrite>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

它工作正常.但是,我现在需要强制应用程序从HTTP重定向到HTTPS.为了做到这一点,我可以添加一个新规则,如下面的帖子描述的:Angular 2 - 总是重定向到https://而不是使用http://

规则强制HTTPS:

<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <clear />
            <rule name="Redirect to https" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

此规则也适用,但它将我的重定向分解为先前定义的根规则.那么有没有人有一个想法我如何将这两个规则混合在一起或以其他方式实现这两个目的?

iis https redirect url-rewrite-module angular

11
推荐指数
2
解决办法
6551
查看次数

IIS 7.5 URL重写模块,包含不存在的文件,没有扩展名

我正在成功使用IIS URL重写模块用于已知的文件扩展名(.aspx,.html等)但是,如何将IIS URL重写模块用于没有扩展名的请求或不存在的文件?

例如:

http://www.example.com/products

应该重定向到我的重写映射中的URL.

我已经尝试将其放入我的重写映射中,但我从IIS获得了404.4"No Handler Specified"错误.

iis iis-7 url-rewriting iis-7.5 url-rewrite-module

10
推荐指数
0
解决办法
7159
查看次数

在IIS重写规则中排除路径?

我有一个重写规则,将URL转换为小写.我想排除一个文件夹,但不知道RegEx.如何从下面的规则中排除"〜/ myfolder"?

  <rewrite>
        <rules>
            <rule name="LowerCaseRule1" stopProcessing="true">
                <match url="[A-Z]" ignoreCase="false" />
                <action type="Redirect" url="{ToLower:{URL}}" />
            </rule>
        </rules>
    </rewrite>
Run Code Online (Sandbox Code Playgroud)

regex url-rewriting iis-7.5 url-rewrite-module

10
推荐指数
1
解决办法
9798
查看次数

Yii2/PHP/IIS7 - URL重写和文件权限(漂亮的URL问题)

我有一个带有以下文本的web.config文件,虽然与我的问题无关...

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Pretty URL">
                    <match url="." ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <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" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

通常当我在我的Windows机器上开发时,带有我的PHP源的文件夹对所有经过身份验证的用户都有权限,而我Yii2网站中的漂亮URL工作没有任何问题.

现在,我的下一个项目要求我部署在非管理员用户也将使用的Windows机器上,我测试了将Yii2网站部署到一个文件夹,使IUSR用户能够列出,读取和执行文件.

该网站有效,但漂亮的网址没有.

如果我使用常规身份验证的用户和SYSTEM权限将文件夹内容复制到另一个位置,它将按预期工作.

我想我缺少一些权限,可以使漂亮的URL与IIS7 URL重写模块一起正常工作,但不确定是什么.

php iis-7 pretty-urls url-rewrite-module yii2

10
推荐指数
1
解决办法
299
查看次数

IIS URL重写不使用查询字符串

我认为这很简单,但它拒绝工作.旧的URL是

http://www.site.com/?q=node/17

它需要重定向到http://www.site.com.我不需要担心通配符,这是我唯一需要担心的查询字符串参数.我写的规则看起来像

<rule name="Node17" patternSyntax="ExactMatch" stopProcessing="true">
    <match url="http://www.site.com/?q=node/17" />
    <action type="Redirect" url="http://www.site.com" appendQueryString="False" />
</rule>
Run Code Online (Sandbox Code Playgroud)

我可以测试IIS内部的模式并匹配,但是当我在浏览器中点击URL时它不会重定向.有什么想法吗?

iis url url-rewrite-module

9
推荐指数
2
解决办法
2万
查看次数

尝试将HTTP重定向到HTTPS(C#,IIS),但HTTPS在响应头中转回HTTP - 重定向循环

我在同一个IIS服务器上设置了两个IIS网站.网站A包含大部分内容,这是用户在请求我们的地址时显示的内容(例如www.websitea.com).网站B是一个单独的项目,只包含整个内容的一部分,因此它是内部的(在IIS中绑定到websiteb.com),但通过URL重写,用户可以通过键入www.websitea.com/websiteb来访问它.

URL重写在网站A的web.config中如下所示:

<rewrite>
  <rules>
    <clear />
    <rule name="Website B rewrite rule" stopProcessing="true">
      <match url="^websiteb(.*)" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{CACHE_URL}" pattern="^(https?)://" />
      </conditions>
      <action type="Rewrite" url="{C:1}://websiteb.com{R:1}" />
    </rule>
  </rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)

{CACHE_URL}和{C:1}位用于保持使用的协议.例如,在HTTP上请求www.websitea.com/websiteb/foo.html的用户在HTTP上被"重写"到websiteb.com/foo.html,并且在HTTPS上对websitea.com/websiteb/bar.html的请求被"重写" "到HTTPS上的websiteb.com/bar.html.

现在,对于某些网站B页面,我们希望用户仅使用HTTPS - 这在我们的SomePageViewModel的ShouldBeHttps属性中设置.因此,在ActionFilterAttribute中使用以下代码:

    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        if (filterContext.HttpContext.Request.IsSecureConnection)
            return;

        var result = filterContext.Result as ViewResult;
        if (result != null)
        {
            if ((result.Model as SomePageViewModel).ShouldBeHttps)
            {
                HandleNonHttpsRequest(filterContext);
            }
        }
    }

    protected virtual void HandleNonHttpsRequest(ActionExecutedContext filterContext)
    {
        if (!string.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
            throw new InvalidOperationException("The method must be …
Run Code Online (Sandbox Code Playgroud)

c# iis https redirect url-rewrite-module

9
推荐指数
1
解决办法
636
查看次数