• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

dynamically add www before my domain name url

When some one types in mydomain.com/about.aspx I need to dynamically place www. before the domain name if it is not present: www.mydomain.com/about.aspx. Can some one tell me the best way to accomplish this?

Thanks.
0
RCairns54
Asked:
RCairns54
  • 2
  • 2
1 Solution
 
ICaldwellCommented:
This is usually something controlled at the web server.... one web server is just setup to take every request, add the www. onto it and then post back, this can be done in a request string....

Question is do you want to take this much time to do it or just setup your main website with your IP of your server and set an alias for www to your main server, that way both ways will work.

Personally I would not redirect users but let them have the option of having it or not, both will work...
0
 
RCairns54Author Commented:
Thanks for your quick reply.

I have iis set up to handle both the domain and the www subdomain requests, but for seo reasons I need to have the www in the url every time. I have used 301 redirects but this is pretty static and takes you to one base url. I thought about handling the request at the app level, caching the url and adding www to the string and redirect but I was hoping to find a way to do this outside of the web app.

Here is an example of what I'm looking for:
If you go to www.bing.com and preform a search and then delete the www. off the url and hit enter it adds it back. This is basically the effect Im looking for.
0
 
ICaldwellCommented:
are you using IIS 7?  If so you could use the URL rewriting to redirect non www to www...

http://weblogs.asp.net/owscott/archive/2009/11/27/iis-url-rewrite-rewriting-non-www-to-www.aspx

This is from the article and I think is exactly what your looking for:

For the Action Properties, enter http://www.domain.com/{R:0}.  The {R:0} retains the existing URL so if someone typed something like http://domain.com/aboutus it would retain the aboutus as it adds the www
0
 
RCairns54Author Commented:
Sweet. Thanks for pointing me in the right direction.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now