iis6上的IIRF - 几个域到一个ip重定向到不同的索引页面

时间:2014-04-09 09:34:44

标签: asp.net rewrite url-redirection iirf

我说英语不好:) - 对不起〜

我有一台服务器托管。 (一个ip)

此Web服务器有三个索引页。

default.asp // s1_default.asp // s2-default.asp

我有三个域名。 aaa.com&两个免费的子域名。 (s1.free.com,s2.free.com ex)

我为iis6安装了iirf。

我想重写或重定向到aaa.com -------> default.asp s1.free.com ---> s1_default.asp s1.free.com ---> s1_default.asp

感谢!!!

1 个答案:

答案 0 :(得分:1)

我认为本教程将帮助您,甚至为您提供替代解决方案的专业和反对意见。 http://www.seoconsultants.com/windows/isapi/subdomains/

来自链接教程的引用:

  

设置DNS服务器

     

将以下条目添加到DNS服务器中,并相应地更改域名和IP地址。

     

* .example.com IN A 1.2.3.4

     

设置Web服务器

     

我们假设您已经为主站点创建了一个网站:www.example.com。因此,我们只需仔细检查即可确保它能够接受子域的所有变体。

     

打开IIS管理控制台并选择您的网站。   右键单击它并选择“属性”。   单击“网站”选项卡。   单击“高级”按钮。   确保此网站的多个标识下的一个条目具有主机标题名称字段为空。此条目将拦截到达此IP地址的所有请求。   确保IP地址仅供本网站使用。   为ISAPI_Rewrite设置httpd.ini

     

将以下代码添加到Web根目录中的httpd.ini。确保它们的顺序正确。

# Convert http://example.com to http://www.example.com/
RewriteCond Host: ^example.com
RewriteRule (.*) http\://www\.example.com$1 [I,RP]

# Assuming we have limited number of shared folders.
# We will execute them accordingly regardless of the subdomain.
# Example: http://sub1.example.com/img/logo.jpg -> /img/logo.jpg
# Example: http://www.example.com/img/logo.jpg -> /img/logo.jpg
RewriteRule (/css/.*) $1 [I,O,L]
RewriteRule (/js/.*) $1 [I,O,L]
RewriteRule (/img/.*) $1 [I,O,L]

#Redirect all other subdirectories not matching
#to the list above as subdomains
#example: www.example.com\sub1 -> sub1.example.com
RewriteCond Host: www\.example\.com
RewriteRule /(\w*)/(.*) http\://$1\.example\.com$2 [I,RP]

# If the web site starts with www then point the file to the root folder
# If you specifically created a folder /www/ then you can comment out this section.
RewriteCond Host: (?:www\.)example.com
RewriteRule (.*) $1 [I,O,L]

# Any web site starts other than www will be re-mapped to /<subdomain>/
# Example: http://sub1.example.com/default.asp -> /sub1/default.asp
# Note: if the folder does not exists, then the user will get a 404 error automatically.
RewriteCond Host: (.*)\.example.com
RewriteRule (.*) /$1$2 [I,O,L]

#Fix missing slash char on folders
#This has to be at the end because if invalid dir exists,
#we should show 404 first
RewriteCond Host: (.*)
RewriteRule ([^.?]+[^.?/]) http\://$1$2/ [I,RP]
  

测试子域名

     

假设我们有公司网站和两个子域名:sub1,sub2。

     

服务器上的URI位置

http://www.example.com  /
http://sub1.example.com/img/logo.jpg    /img/logo.jpg
http://sub2.example.com /sub2/
http://abc.example.com  /abc/ -> 404 Not Found
  

解决方案2:摘要

     

第二种解决方案更容易实现,只需要一个网站实例,用户必须小心创建文件夹。例如,用户无法创建文件夹d:\ inetpub \ wwwroot \ example.com \ sub1 \ img \,因为它会与(/img/.*)的ISAPI_Rewrite规则冲突。因此,无法访问该文件夹中的文件。