asp.net - 使用 web.config 规则重定向到子域
问题描述
我们迁移托管在主域内的目录“webapp”中的 webapp:
http://www.example.com/webapp/
到没有“webapp”文件夹的新子域:
http://subdomain.example.com/
我只需要重定向子目录“webapp”。我不想重定向其他网址,如http://www.example.com/
, http://www.example.com/folder1
, http://www.example.com/folder2
, ....
但是我们已经向客户发送了很多电子邮件,其中包含以下链接:<a href="http://www.example.com/webapp/login">LOGIN TO YOUR DASHBOARD</a>
或其他链接,例如<a href="http://www.example.com/webapp/data/download.php/id=xxx">DOWNLOAD YOUR DOC</a>
现在我正在尝试通过 web.config 进行重定向,但似乎没有任何效果。
例如,如果我尝试不导航到,http://www.example.com/webapp/login
我不会http://subdomain.example.com/login/
按预期重定向到。
例如,如果我尝试不导航到,http://www.example.com/webapp/data/download.php/id=43
我不会http://subdomain.example.com/data/download.php/id=43
按预期重定向到。
有什么建议吗?
<rule name="redirect-to-subdomain" stopProcessing="true">
<match url="^webapp/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="http://subdomain.example.com/{R:0}" redirectType="Permanent" />
</rule>
解决方案
除了http://www.example.com/webapp/之外,您的规则将不起作用。
如果您想重定向链接,例如http://www.example.com/webapp/login。请试试这个规则。
<rule name="redirect-to-subdomain" stopProcessing="true">
<match url="^webapp/(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="http://subdomain.example.com/{R:1}" redirectType="Temporary" />
</rule>
推荐阅读
- r - 用 dplyr 中因子变量的模态值替换 NA 值
- javascript - 是否可以将消息从电子 IpcRenderer 发送到网页内的 html iframe?
- c - 主函数中的 printf 在 C 中返回两次
- c - 使用 Linux 'perf' 以编程方式测量 L2 缓存相关的原始计数器
- python - Shutil 正在目标文件夹中制作两个副本
- c - 可移植地确定 C 中文件的大小
- android-recyclerview - 使用 LiveData、Room 和 DiffUtil 更新 RecyclerView 项目内的内部视图
- javascript - 如何在jsx中调用变量
- elasticsearch - 具有分组数据的 Elastic Search Metric 可视化
- python - 纸浆:在循环中添加多个 LpSum