2

I want to do some testing on my Windows 2008 R2 server. That is, let a URL redirect to localhost.

For example, let "http://mysample.mydomain.com/index.html" actually accesses "http://localhost/index.html". Is there any way I can do this?

I tried to edit the windows\system32\drivers\etc\hosts file, adding 127.0.0.1 -> mysample.mydomain.com mapping, but it doesn't work. It seems 127.0.0.1 and localhost are not identical. I can access "http://localhost/index.html", but I can't access "http://127.0.0.1/index.html"!

Thanks in advance!

1
  • I think this should be migrated to superuser.com
    – Kent Pawar
    Oct 16, 2012 at 17:08

2 Answers 2

0

Write class that inherits from System.Web.UI.Page then override on load:

public abstract class CorePage : Page
{
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        //TODO: check request url and make a redirect if required!

    }
}

Change all your pages to inherit from CorePage and job is done! This will of course work only for aspx pages on application level not for entire IIS.

1
  • I want to do this with my IE.
    – quantity
    Sep 3, 2012 at 9:20
0

Since you are on a Windows 2008 R2 server, I guess you are using IIS for your test. Also note that Windows Server 2008 is the first version of Windows to "enable" IPv6 by default - but is your IPv4 version enabled too...?

Enable IPv4: [Control panel > Network and sharing center > Change adapter settings > Right click the adapter used for connectivity and select properties > See if IPv4 is checked. ]

I think your localhost is internally been resolved to use ::1 (IPv6) loopback address. You can confirm this by checking:

For IPv6 test: ping localhost -6 and for IPv4 test: ping localhost -4. If it resolves to ::1, its using the IPv6 address.

Your \etc\hosts file should have the following entries:

::1 locahost mysample.mydomain.com

Now do a ping test as ping mysample.mydomain.com -6. This should confirm that mysample.mydomain.com has been resolved to your local loopback address using IPv6.

Refer:

  1. Difference-between-127-0-0-1-and-localhost
  2. Localhost

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.