2009-08-21 128 views
0

我想implemewnt URL重写的方式,用户可以通过访问username.domain.com网站URL重写在ASP.Net

例如
www.abc.com/login.aspx
我应该能够访问此像
www.username.abc.com/login.aspx

的blogspot也喜欢http://username.blogspot.com/

的例子之一

Plz建议我怎么做到这一点。

感谢

+0

我可能是错的,但我不知道可以使用与使用子域相同的方式进行URL重写。如果这是你必须通过IIS做的事情,我相信。 – 2009-08-21 08:19:17

回答

2

基本上你需要做的是使用一个工具,如Managed Fusion URL Rewriter and Reverse Proxy,用下面的规则。

RewriteCond {HOST} www\.(.*)\.abc\.com 
RewriteRule ^/login.aspx$ /login.aspx?domain=%1 
RewriteRule ^/login.aspx?domain=www\.(.*)\.abc\.com$ /login.aspx?user=$1 

所以它会通过对您的内部应用程序一样

URL: www.nick.abc.com/login.aspx 
Internal URL: www.abc.com/login.aspx?user=nick 

你必须解决哪些你没有地址是你怎么得到用户名的事情,你怎么样在内部处理它们。

但实际上你不需要URL重写器。您只需将所有DNS流量转发到相同的IP地址,然后在您的应用程序中处理域名,而不是通过DNS控制域名。

+0

这些规则应该放在ManagedFusion.Rewriter.txt文件中吗? – 2009-09-04 07:35:46

+0

是的,他们应该放在那里,显然你的规则会比我上面发布的规则有所不同。 – 2009-09-04 22:06:36

+0

访问http://rt.nexapps.com/Login.aspx时遇到异常plz检查谢谢 – 2009-09-07 11:53:23

0

很可能与服务器上安装的ISAPI重写

你必须把这个网站

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

的文件的httpd.ini的重要组成部分,这是一个:

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

这是我能找到的最好的方法。如果您无法访问服务器,并且没有安装ISAPI,那么这不适合您。

这里的链接文章 http://www.seoconsultants.com/windows/isapi/subdomains/

0

在web配置试试这个下的System.Web

<system.web> 
    <urlMappings enabled="true"> 
     <add url="~/myaccount" mappedUrl="myaccount.aspx"/> 
    </urlMappings> 

在隐藏文件中的代码编写

Response.redirect("~/myaccount")` 

这个工程100%