URL重写产生404 [英] URL rewrite is producing 404

查看:140
本文介绍了URL重写产生404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下规则将 office.domain.com/app1 请求重写为 server3:81 ,但我得到的是404.我可以浏览 server3:81 就好了。

I'm trying to rewrite office.domain.com/app1 requests to server3:81 using the rule below, but I'm getting a 404. I can browse to server3:81 just fine.

失败的请求跟踪日志可用这里,但它们似乎没有透露太多。

The Failed Request Tracing logs are available here, but they don't seem to reveal much.

我也试过 url =http:// server3:81 / {R:0} url =http:// server3:81 / {R:1}(不知道为什么/差异是什么),但两者都产生相同的结果(404)。

I've also tried url="http://server3:81/{R:0}" and url="http://server3:81/{R:1}" (not sure why/what the difference is), but both produce the same result (404).

我的规则中我做错了什么? (警告:我对RegEx还不太感兴趣,但我会尽力理解你的答案。我可能要求澄清。)

What am I doing wrong in my rule? (Warning: I'm pretty unhandy with RegEx just yet, but I'll do my best to understand your answer. I may have to ask for clarification.)

<rule name="App1" stopProcessing="true">
  <match url="^app1" />
  <action type="Rewrite" url="http://server3:81/" />
</rule>


推荐答案

您可能想尝试一些事情,第一种方法是更改​​正则表达式模式以匹配您要替换的整个网址并捕获您要保留的部分。第二个建议是验证您的重写网址是 http 而不是 https

There's a couple of things you might want to try, the first would be to change the regex pattern to match the entire url you are replacing and capture the part you want to keep. The second suggestion would be to verify that your rewrite url is http and not https:

方法一:(正则表达式更改)

<rule name="App1" stopProcessing="true">
 <match url="^.*/(app1)" />
   <action type="Rewrite" url="http://server3:81/{R:1}" />
</rule>

方法二:(正则表达式+ https +端口更改)

Method Two: (regex + https + port change)

<rule name="App1" stopProcessing="true">
 <match url="^.*/(app1)" />
   <action type="Rewrite" url="https://server3:8080/{R:1}" />
</rule>

方法三:(正则表达式完整网址+相对重写)

Method Three: (regex full url + relative rewrite)

<rule name="App1" stopProcessing="true">
 <match url=".*" />
   <action type="Rewrite" url="server3:81/app1" />
</rule>

这篇关于URL重写产生404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆