views:

389

answers:

3

I want to implemewnt URL-Rewriting in way that user can access website with username.domain.com

e.g.
www.abc.com/login.aspx
I should be able to access this like
www.username.abc.com/login.aspx

blogspot is also one of the example like http://username.blogspot.com/

Plz suggest me how can I accomplish this.

Thanks

A: 

Please have a look at following links:

http://www.codeproject.com/KB/aspnet/LocalizedSamplePart2.aspx http://gallery.menalto.com/node/88189

adatapost
that is not I am looking for, such kind of URL Re-Writing, I have already implemented
Muhammad Akhtar
what I am looking for is like that http://username.blogspot.com/
Muhammad Akhtar
The real napster solution is closed to what I required
Muhammad Akhtar
A: 

It is possible with ISAPI Rewrite installed on the server

You have to put this in the httpd.ini file of the website

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

The vital part is this one:

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

This is the best way I could find. If you don't have access to the server sittings and don't have ISAPI installed then this is not for you.

Here's the link to the article http://www.seoconsultants.com/windows/isapi/subdomains/

The real napster
+1  A: 

Basically what you need to do is use a tool like the Managed Fusion URL Rewriter and Reverse Proxy, with the following rule.

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

So it will come through to your internal application like

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

The thing you have to solve which you didn't address is how are you going to get the users name and how are you going to handle them internally.

But really you don't need a URL Rewriter. You just forward all DNS traffic to the same IP address, and then you handle the domain with in your application instead of controlling it through the DNS.

Nick Berardi
these rules shoule be put in ManagedFusion.Rewriter.txt file?
Muhammad Akhtar
yes they should be put in there, obviously your rules are going to differ than the ones I posted above.
Nick Berardi
getting exception when accessing http://rt.nexapps.com/Login.aspx plz check thanks
Muhammad Akhtar
Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Muhammad Akhtar
as my problem still not resolved, you have cooperate me very well and giving quick respond, I am very grateful and thankful for your kind help.. so I am marking your answer and upvoting... Thanks again..
Muhammad Akhtar