Coolenough
Coolenough

Reputation: 533

How to change domain .net to .com using JavaScript

I have small query today I happen to see when I typed a website "http://www.websitename.net"

it automatically got converted to "http://www.websitename.com" i.e., .net to .com and then the page as loaded.

I am eager to know how it has been done.

Upvotes: 0

Views: 122

Answers (2)

Steve H.
Steve H.

Reputation: 6947

Your browser assumes you might have made a mistake (when the host is not found) and will try alternate (common) domains. This is assuming that the site does not exist.

If this is happening on a site that DOES exist (such as when you go to wikipedia.com), a redirect (HTTP 302 - Moved Temporarily) will be returned.

Upvotes: 0

Eric J.
Eric J.

Reputation: 150138

This is generally done as a server-side redirect.

You can watch the network traffic and see for yourself what happens. For example in IE9, use the Developer Tools (F12), click the Network tab, and click the "Start capture" button to start monitoring. Other browsers have similar features.

In the Response headers you'll see something like

Key         Value
Response    HTTP/1.1 301 Moved Permanently
Location    http://mywebsitename.net

Upvotes: 1

Related Questions