Domanda

I can not speak English well :) - sorry~

I have one server hosting. (one ip)

and this web server has three index pages.

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

I have three domains. aaa.com & two free sub domains. (s1.free.com, s2.free.com ex)

I've installed iirf for iis6.

I want rewrite or redirect to aaa.com -------> default.asp s1.free.com ---> s1_default.asp s1.free.com ---> s1_default.asp

Thanks!!!

È stato utile?

Soluzione

I think this tutorial will help you and even give you some pro and contra for an alternative solution. http://www.seoconsultants.com/windows/isapi/subdomains/

Quote from the linked tutorial:

Setup DNS Server

Add the following entry into your DNS server and change the domain and IP address accordingly.

*.example.com IN A 1.2.3.4

Setup the Web Server

We are assuming that you already have a web site created for your main site: www.example.com. So let's just double check to make sure it will be able to accept all variations of the subdomains.

Open IIS Management Console and select your web site. Right click on it and select Properties. Click on Web Site tab. Click on Advanced button. Make sure there is one entry under the Multiple identities for this Web Site with Host Header Name field blank. This entry will intercept all requests that comes to this IP address. Make sure the IP address is only used by this web site. Setup httpd.ini for ISAPI_Rewrite

Add the following code to your httpd.ini in the web root. Make sure they are in the correct order.

# 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]

Test the Subdomains

Assuming we have the company website and two subdomains created: sub1, sub2.

URI LOCATION ON SERVER

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

Solution 2: Summary

The second solution is easier to implement and only requires one instance of the website, the user has to be careful about creating the folders. For example, the user can not create a folder d:\inetpub\wwwroot\example.com\sub1\img\ because it would conflict with the ISAPI_Rewrite Rule of (/img/.*). Therefore the files in that folder will not be accessible.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top