0

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

1
  • I can be wrong but I don't know if it's possible to URL rewrite the same way you use subdomains. If it is it is something you have to do via IIS I am sure. Commented Aug 21, 2009 at 8:19

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

these rules shoule be put in ManagedFusion.Rewriter.txt file?
yes they should be put in there, obviously your rules are going to differ than the ones I posted above.
getting exception when accessing rt.nexapps.com/Login.aspx plz check thanks
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.
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..
0

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/

Comments

0

Try this in web config under system.web

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

in code behind file write

Response.redirect("~/myaccount")`

This works 100%

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.