Squ*_*ing 5 subdomain redirect web-config
是否可以将不正确的子域(不存在的子域)重定向到某个页面(自定义错误页面)?
编辑:使用web.config文件
例如,如果我键入http://foo.squishling.co.uk/,它将重定向到http://squishling.co.uk/errors/incorrect_subdomain.html/,如http://foo.squishling. co.uk/不是正确的子域名.
我没有看到任何代码执行此操作,所以它可能吗?
编辑:如果不可能,请说出来
在此先感谢,~Squishling
编辑:如果这是可能的,一个可能的方法是当服务器收到不正确的子域的请求,只是欺骗请求请求错误页面
是的,这是可能的。以下是 IIS 10 + UrlRewrite 2.1 的使用方法。
例如,我们假设我有:
good.localhost:81/error.txtIIS 管理器 -> 网站上下文菜单 ->“编辑绑定..”编辑接受的主机名以接受*.<yourDomain>. 对于示例情况:

现在网站应该同时响应http://good.localhost:81和http://bad.localhost:81。
您可以从这里找到 URL 重写模块安装程序: https: //www.iis.net/downloads/microsoft/url-rewrite
虽然您可以使用 IIS MANager 的 GUI 来实现此目的,但您也可以将如下内容手写到您的 web.config 中:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="DirectBadSubdomainsRule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^good\.localhost:81" negate="true" />
</conditions>
<action type="Redirect" url="http://good.localhost:81/error.txt" redirectType="Temporary" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
您可以使用正则表达式的强大功能来确定哪些子域有效,哪些子域无效。您还可以准确决定所需的重定向代码。上面的示例使用临时重定向 (HTTP307)。
这里有很多文档: https: //www.iis.net/downloads/microsoft/url-rewrite
不良域名现在应该返回重定向响应:
| 归档时间: |
|
| 查看次数: |
589 次 |
| 最近记录: |