Forum Moderators: open

Message Too Old, No Replies

IIS Check whether a URL contains www

         

dukelips

6:04 pm on Jul 13, 2009 (gmt 0)

10+ Year Member



is there any other way to check whether a url is having www or not.(except javascript)

phranque

11:18 pm on Jul 13, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you can check the presence or absence of "www" in a string in any language that supports regular expressions.
if you are looking for a method to check the url of the current page in the user agent, you could probably use java or flash as well as javascript.

dukelips

12:43 am on Jul 14, 2009 (gmt 0)

10+ Year Member



We are using asp, is there any other way to automatically add www to a url.
For eg:
example.com - www.example.com

JohnRoy

1:15 am on Jul 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Once the page is displayed, you cannot just "add" the www.
The (non www) page needs to then be redirected (301) to the www.page
if Request.ServerVariables("server_name")="example.com" then 
Redirect301 = www.example.com/page_path_and_name
end if

phranque

2:24 am on Jul 14, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you don't want to do this "on the page" or in the user agent.
the correct way to do this is in the server with a "Moved Permanently" (301) response as JohnRoy suggested.
this is called "domain canonicalization [google.com]" and there are several methods for doing this on an ASP server.

dukelips

4:32 am on Jul 14, 2009 (gmt 0)

10+ Year Member



what will happen to the pages inside the directories after the redirect

dukelips

4:38 am on Jul 14, 2009 (gmt 0)

10+ Year Member



I just selected the third option "redirect to a url" in iis and it works fine.

Phranque & John , my heartfelt thanks for ur help.

We have a got a ssl for a domain www.example.com and we dint people to access directories through sub domains.

phranque

6:52 am on Jul 14, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



make sure to also check the box for "A permanent redirection for this resource" so that it properly sends a 301 response code.

marcel

8:08 am on Jul 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If there are deep-links from other sites to the non-www version of your site that you cannot edit, you can use the following syntax in the 'redirect to a URL' textbox:

http://www.example.com$S$Q

This will pass the subdirectory and querystring to the new domain.

Here is a list of other options from Microsoft Technet [microsoft.com]

dukelips

8:27 am on Jul 14, 2009 (gmt 0)

10+ Year Member



We use IIS 5 and is it similiar for both 5 and 6