Sometimes you may need to redirect all web traffic to another website or another page within your site but you still want to be able to view your website. This is common when you are making changes that you are not ready for others to see just yet or when you are performing maintenance. In this article, we will discuss How to Redirect all Visitors Except One IP to Another Website.
In this Guide: Take me to the .htaccess Code
You can achieve this in a few simple steps using the .htaccess file which is located in the document root of your website. To edit your .htaccess file, you will need to access File Manager in your cPanel account.
How to Redirect all Visitors Except One IP to Another Website
Edit Your .htaccess file via File Manager:
2. Click on ‘File Manager‘
3. Navigate to the document root for your website.
4. Locate the ‘.htaccess‘ file in the list. Click once on the file to highlight it, then right click on the file and select ‘edit‘.
Click on ‘Edit‘ again in the prompt to open the file for editing.
Note! .htaccess is considered a dot file. In File Manager, dot files are hidden by default. You will need to “unhide” them in the settings in file manager to see your .htaccess file.
→ Click Here to Learn How to Show Hidden (dot) files in File Manager
5. With the .htaccess file open in the editor, paste the following code into the next line in the file:
RewriteEngine On RewriteBase / RewriteCond %{REMOTE_HOST} !^1.2.3.4 RewriteRule .* https://www.newwebsiteurl.com [R=302,L]
In the code above:
- Replace 1.2.3.4 with your IP address. (Click here to View Your IP address)
- Replace ‘https://www.newwebsiteurl.com’ with the address for the Website you want to redirect visitors to instead.
Example:
6. Click ‘Save‘ to save your changes!
That’s it! You should be able to browse to your website from your IP address but all other visitors should be redirected to the URL you specify.