我的生产设置如下:
使用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.它也只能针对某些重定向.大多数情况下,这里提到的行为是必需的,因为所有重定向都被重定向到主代理服务器.有人可以为某些重定向建议解决方案或解决方法吗?
我有一个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=([^=&]+)$" />
</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)
我尝试了很多方法,包括路径信息......但没有成功.也许有人可以暗示一下?
谢谢!
我已经阅读过几个组合的前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重写模块中使用重写映射)但是,正如我在那里评论的那样,这似乎与在该文本之前给出的具体示例相关,而不是批发"这可能永远不会起作用" …
我想在IIS中设置反向代理,但在我的配置中,我遇到了ASP.NET回发的问题.当您单击代理网站的任何提交按钮时,您会收到404错误.浏览器地址栏中的URL更改为重写的URL.
例如,我需要代理的网站是http://website.com/host.这里http://website.com和http://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) 我在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 URL重写模块用于已知的文件扩展名(.aspx,.html等)但是,如何将IIS URL重写模块用于没有扩展名的请求或不存在的文件?
例如:
http://www.example.com/products
应该重定向到我的重写映射中的URL.
我已经尝试将其放入我的重写映射中,但我从IIS获得了404.4"No Handler Specified"错误.
我有一个重写规则,将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) 我有一个带有以下文本的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重写模块一起正常工作,但不确定是什么.
我认为这很简单,但它拒绝工作.旧的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服务器上设置了两个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)