[英]Map Domain Alias to Virtual Folder in IIS6
我怎么能去映射域别名,如domainAlias.co.za
下,以一个虚拟文件夹,例如mainDomain.co.za
,让所有请求domainAlias.co.za
实际上得到的服务mainDomain.co.za/domainAlias
?
A URL Rewriter like IIRF lets you do this. 像IIRF这样的URL重写器使您可以执行此操作。
The rules would be: 规则是:
RewriteCond %{HTTP_HOST} ^(?!mainDomain)([^\.]+)\.co\.za$
RewriteRule ^/(.*)$ /%1/$1 [L]
In English, this rule says: if the host is NOT maindomain.co.za, but still ends in .co.za, then rewrite the URL so that it is prepended with /domainAlias/. 用英语来说,此规则说:如果主机不是maindomain.co.za,但仍以.co.za结尾,则重写URL,以便在它前面加上/ domainAlias /。 With this rule, you get:
使用此规则,您将获得:
input output
----- ------
http://foo.co.za/a.php http://main.co.za/foo/a.php
http://foo.co.za/a.aspx?r=1 http://main.co.za/foo/a.aspx?r=1
You can also go one level further and make the rewrite conditional on the presence of the directory, something like this: 您还可以再上一层,使重写取决于目录的存在,如下所示:
RewriteCond %{HTTP_HOST} ^(?!mainDomain)([^\.]+)\.co\.za$
RewriteCond c:\wwwroot\%1 -d
RewriteRule ^/(.*)$ /%1/$1 [L]
This says: if the host is not maindomain.co.za, AND the directory c:\\wwwroot\\domainAlias exists, then rewrite to prepend .... 这表示:如果主机不是maindomain.co.za,并且目录c:\\ wwwroot \\ domainAlias存在,则重写为prepend...。
But in that case you might instead want to do the converse - test for lack of existence of the directory - and redirect to a 404: 但是在那种情况下,您可能想做相反的事情-测试目录是否不存在-并重定向到404:
RewriteCond %{HTTP_HOST} ^(?!mainDomain)([^\.]+)\.co\.za$
RewriteCond c:\wwwroot\%1 !-d
RewriteRule ^/(.*)$ - [NF]
NF = 404 因子= 404
you can also do [F] which is a 503 (Forbidden). 您也可以执行[F],即503(禁止)。
IIRF works on IIS5, IIS6, or IIS7. IIRF可在IIS5,IIS6或IIS7上运行。
您可以使用路由。
System.Web.Routing
I haven't used it, but IIS has a URL Rewrite Module that can import Apache mod_rewrite rules . 我没有使用过它,但是IIS有一个URL重写模块 ,可以导入Apache mod_rewrite规则 。 There is also a document that compares IIS URL Rewriting and ASP.NET routing .
还有一个文档比较了IIS URL重写和ASP.NET路由 。 With some research, you should be able to get that working.
通过一些研究,您应该能够使它工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.