Is there a way to always require or force the www subdomain on a site?

I want users to not be able to tell example.com and just go to www.example.com, we use IIS 6. So say they go to example.com, which it can link to www.example.com , and etc.

Is this a parameter somewhere or will I need to encode it to check the subdomain when they land and redirect accordingly?

EDIT: I know the best way is to move away from the www prefix, but for some reason, if a user runs a course (this is LMS) without www in the URL, tracking does not work for the .asmx file, so I'm trying to force "www "because if some people don’t have this, they wonder why tracking doesn’t work.

+4
source share
11 answers

Since both entries already point to the correct server ...

... you could just create a new website in IIS (server version required) and give it an answer only to example.com (host header parameter) and redirect it to the desired URL (check the redirect to url in the Home Directory and enter www.example.com). The original site should handle it (you can set its host header to more accurately respond to www.example.com).

If you cannot do this on a web server, your publishing firewall should be able to, or you might consider replacing it. Your DNS provider may also provide (pun intended) a forwarding service (doing basically the same thing as above for you, I think).

+5
source

If you are using ASP.NET to create an HttpModule, handle the BeginRequest event and add this code to your handler:

HttpApplication application = (HttpApplication)source; HttpContext context = application.Context; if (context.Request.Url.Host == "example.com") { context.Response.Clear(); context.Response.Status = "301 Moved Permanently"; context.Response.AddHeader("Location", "http://www.example.com" + context.Request.RawUrl); } 

Note that I did not use Response.Redirect (), this is for SEO, since Response.Redirect () always returns 302, which means the object was temporarily moved, and 301 status means that the object was moved permanently On the basis of this, it will not be possible to split the PageRank of your pages between versions of www and non-www (if search engines can access the page using both WWW and non-WWW addresses, they will share your PageRank between the two, therefore, this is 301 search engines understand and will only keep your PageRank in the www-version of your site).

+6
source

As in other answers, redirect 301 redirects on behalf of an uncertified domain to a site with the www. prefix www. .

Given that I really work in the DNS industry, I would like to share my views on the www. discussion www. :

So far, at least IMHO, the preferred version of the URLs should be prefixed with www. . Part of the hostname of the URL is exactly what the hostname is . The only DNS resource records that your browser will look for are A records (and possibly AAAA for IPv6), and the resulting IP address is the one to which it will connect.

no website address - only the full URL (prefixed with http:// ) indicates that this host is waiting for HTTP connections on port 80.

In general, the reason for the www. prefix www. was to allow the separation of different protocols into different hosts. As Verisign showed, when they (briefly) introduced their SiteFinder service several years ago, believing that each request for an A record to use the HTTP protocol is a massive mistake.

Having a canonical version of your URL with the www. prefix www. It also simplifies the processing of cookies and makes it easier to split static content into a content delivery network (as recommended by Yahoo !, Google, etc.).

Now there is a type of DNS record ( SRV , see RFC 2782 ) that uses the service and transport prefix to allow a single domain name to send different protocols to different hosts (and therefore IP addresses).

An ideal DNS setup is a record that looks like this:

 _http._tcp.example.com IN SRV 10 0 80 www.example.com. 

This means that all requests for the HTTP URI over TCP / IP should be addressed to TCP port 80 to the host name www.example.com . Note that with this syntax, you can also have HTTP services automatically from ports other than port 80, without the port number being part of the URL.

An SRV is a required part of SIP and is commonly used for Jabber (XMPP). However, AFAIK does not use a browser .: (

+4
source

Contact your host (or your domain registrar) and ask him to configure it to work with or without www. However, it should work in both directions or in only one way if you wanted to. I assume that you have a host and you do not have your own web server / domain name registration, lol.

+1
source

Here's how it works, regardless of whether you want to.

This is handled by DNS. Typically, example.com and www.example.com point to the same server, but they do not need this. If www.example.com is not explicitly registered, the request is sent to the example.com server, and this server can decide what www.example.com, as well as mail.example.com, ftp.example.com, home.example, means. com, users.example.com etc.

Edit: I understand that this story is incomplete, because these days Apache gets the URL you are used to and can interpret the subdomain from it and send a request to the virtual site. But this should not be a factor at the www level.

0
source

A typical way this is done on websites is to redirect HTTP from example.com to www.example.com. You do this by returning either an HTTP status code of 301 (permanent redirect) or 302 (temporary redirect) when the user goes to example.com and sets the HTTP location field in the response http://www.example.com . Google for "301 vs 302" to see when you should use.

Please note that this is an HTTP function, not something provided by DNS ... some domain name providers, however, provide you with the ability to redirect HTTP if you use their name servers.

Please note that you can verify this yourself. Go to http://web-sniffer.net and enter yahoo.com (or microsoft.com or any major website). You will see that they respond to a redirect with a www version of the name (in less common cases, some websites go the other way, redirect www to a non-www version of the name).

0
source

When I had the misfortune of working with the Microsoft web stack, I used ISAPI_Rewrite to force www. prefix (by the way).

0
source

On my website, I just put the following in a .htaccess file:

 RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} ^tafkas\.net$ [NC] RewriteRule ^(.*)$ http://www.tafkas.net/$1 [L,R=301] 
0
source

For Apache based server you can use this code

 RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$ [NC] RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L] 

Explanation: The first line simply enables the rewrite mechanism. The second line of code is checking the URL entered by the user. The sign bash (!) Means not equal. The carrot sign (^) marks the beginning of the statement being verified. Backslash Point (.) Refers to a special period character, which when used without a backslash means β€œanything”. The dollar sign at the end of the statement refers to the end of the URL. The third statement states that if the input specified by users is not the one specified in instruction two, then proceed as follows. (. *) means anything and any number of times. This is used to save anything written by the user after yourdomain.com/ is stored in the variable $ 1. R = 301 refers to a constant call forwarding, and L indicates that this is the last of a series of status codes.

0
source

As indicated, adding WWW is the opposite direction. WWW is currently redundant.

You can check out http://no-www.org/ for more information.

-3
source

This is the opposite. That was in 1998, but now you have to delete www if you need to .

In addition, example.com is specifically reserved for sending example URLs. Someone probably really owns and uses the one you provided. As you know, you are not directing someone to a porn or malicious site with this random example?

-4
source

All Articles