Website redirection is something that websites do when they’ve migrated from one domain to another. It makes it easier for users who still visit the old domain to automatically be redirected to the new one. Of course, URL redirection isn’t just for websites. If you often accidentally visit the wrong domain, you can add a redirection at the OS level. To redirect a URL on Windows 10, you have to edit the hosts file. Here’s what you have to do.
Redirect a URL
The first thing you need to do is decide which URL or which domain you want to redirect to another. Let’s say you intend to visit Google but you accidentally keep visiting Reddit (it happens). This means you need to make it so that Reddit is redirected to Google.
To do that, you must first find the public IP of Google. Open Command Prompt and run the following command.
The first line of output will show you the IP of the website in square brackets. Copy it.
Open the Start Menu and go to the apps’ list. Look for Notepad. Alternatively, use Windows Search to find it. Right-click the app and select ‘Run as administrator’ from the context menu.
Once Notepad is open, use the File>Open option on the menu bar and navigate to the following location.
Open the file type dropdown and change it from text files to all files. Select the hosts file.
Once the hosts file is open, enter the following on a line of its own. Do not add a hash before it
[Redirected IP address] [domain to redirect]
The IP address is where the domain that follows it will be redirected to. The above example will redirect Reddit to Google.
Use the Ctrl+S keyboard shortcut to save the changes. Next, open Command Prompt with admin rights and run the following command.
For good measure, close and re-open any browser you have open. Visit the website and it will be redirected to the IP address you entered. You can do this for as many websites as you want.
You can redirect as many URLs or domains you like and you can redirect them all to different URLs or to the same one. It is entirely up to you. To undo this change, remove the lines you add, flush the DNS again, and restart all browsers.
Sometimes even flushing the DNS doesn’t do the job. In that case, it’s a good idea to restart your system.