简体   繁体   English

IIS 服务器 url 重写

[英]IIS server url rewrite

For example, I have a domain example.com and my server IP is 1.1.1.1 that is running Microsoft IIS server on Windows Server 2016 Datacenter For example, I have a domain example.com and my server IP is 1.1.1.1 that is running Microsoft IIS server on Windows Server 2016 Datacenter
The DNS record is A *.example.com 1.1.1.1 DNS 记录是A *.example.com 1.1.1.1
I want to make the server, 1.1.1.1 display the contents under C:\inetpub\*我想做服务器, 1.1.1.1显示C:\inetpub\*下的内容
If the directory doesn't exist, the server should return a 404 error.如果目录不存在,服务器应该返回 404 错误。

For example:例如:

  • The file system:文件系统:
|--C:\
    |-- inetpub\
        |-- a
        |-- b
        |-- c

will results:将结果:

  • a.example.com show contents under C:\inetpub\a a.example.com显示C:\inetpub\a下的内容
  • b.example.com show contents under C:\inetpub\b b.example.com显示C:\inetpub\b下的内容
  • c.example.com show contents under C:\inetpub\c c.example.com显示C:\inetpub\c下的内容
  • d.example.com return HTTP/1.1 404 Not Found d.example.com返回HTTP/1.1 404 Not Found

Thanks.谢谢。

Please map these folders as virtual directory under your website.请将 map 这些文件夹作为您网站下的虚拟目录。

For example: /a->c:\inetpub\a.例如:/a->c:\inetpub\a。 /b->c:\inetpub\b. /b->c:\inetpub\b.

Then you can easily rewrite a.example.com/test.aspx to a.example.com/a/test.aspx.然后你就可以轻松地将 a.example.com/test.aspx 重写为 a.example.com/a/test.aspx。 If the folder does not exist.如果文件夹不存在。 Then d.example.com/d/ will just return 404.然后 d.example.com/d/ 只会返回 404。

<rule name="rewrite">
    <match url="(.*)" />
        <conditions>
           <add input="{HTTP_HOST}" pattern="(.*)\.example\.com" />
        </conditions>
    <action type="Rewrite" url="{C:1}/{R:1}" />
</rule>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM