How To Redirect A Domain Without Changing The URL

How To Redirect A Domain Without Changing The URL

At times, you want to redirect or forward your existing domain to another one, but do not want to change the URL of the site after redirecting your domain. You want the same old URL before you made the change. In this tutorial, you will learn to redirect a domain without changing the URL.How To Redirect A Domain Without Changing The URL

Prerequisites

  • A Domain name (example.com0
  • cPanel Credentials
  • FTP Client (Filezilla, Cyberduck)
  • Text Editor (Notepad, Sublime Text)

Step 1

Login to your cPanel using your credentials and Locate File Manager. Click File Manager.

How To Redirect A Domain Without Changing The URL

Step 2

Open the .htaccess file located in the public_html directory.

How To Redirect A Domain Without Changing The URL

Step 3

Right-click the .htaccess file and Click on Edit.

It will show up the Edit pop up. Click on Edit button. You can also use an FTP client manager to access the root directory of your site and make changes to the .htaccess file using your favorite text editor.

How To Redirect A Domain Without Changing The URL

Step 4

Add the following line of code in your .htaccess file if you want to redirect your visitors from your old domain to new domain without changing the URL.

If you want your visitors who are coming to example1.com in their browser and want them to redirect to example2.com without changing the URL, then you can add this line for redirection using the .htaccess file. This will enable the content of example2.com to be loaded when a visitor tries to access example1.com.

RewriteEngineOn
RewriteCond%{HTTP_HOST} ^example1.com RewriteRule ^(.*) http://example2.com/$1 [P]

The first line tells Apache to start the rewrite module. The second line specifies the redirect from the source domain to the destination domain.

Step 5

You can even redirect visitors from one domain to a specific page from another domain.

You can set the redirection by adding the following line of codes to your .htaccess file. This will enable your visitor who is visiting example1.com to redirect automatically to a specific page of example2.com or any other website that is mentioned in the redirection rule.

RewriteCond%{HTTP_HOST} ^example1.com RewriteRule ^(.*) http://example2.com/redirectedpage [P]

You can similarly redirect an IP address to a specific website. Add the following line of codes to your .htaccess file.

RewriteCond%{HTTP_HOST} ^192.168.45.11 RewriteRule (.*) http://example2.com/$1 [R=301,L]

L means this is the last rule in this run. After this rewrite is complete, the web server will return a result. The R=301 means that the web server returns a 301 moved permanently to the requesting browser or search engine.

Step 6

Search engines remove the trailing slashes from URLs.

This could sometimes result in a content problem when the same page can be accessed through different URLs. This problem can be solved by writing a .htaccess rule for trailing slashes.

Add the following line of code the .htaccess file.

RewriteEngineOn
        RewriteCond%{REQUEST_FILENAME} !-f
        RewriteCond%{REQUEST_URI} !example.php
        RewriteCond%{REQUEST_URI} !(.*)/$
        RewriteRule ^(.*)$ http://example.com/$1/ [L,R=301]

 

Conclusion

By making some changes to the .htaccess file of your WordPress site, you can easily redirect a domain name to another without changing the URL.

Check out these top 3 cPanel hosting services:

Hostinger
AU$4.66 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.7
  • Support
    4.7
  • Features
    4.8
  • Reliability
    4.8
  • Pricing
    4.7
HostArmada
AU$3.88 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0
FastComet
AU$2.79 /mo
Starting price
Visit FastComet
Rating based on expert review
  • User Friendly
    4.7
  • Support
    5.0
  • Features
    4.8
  • Reliability
    4.5
  • Pricing
    5.0

How To Change Default Index Page In .htaccess From cPanel

This tutorial will help you to change the default index page of your website by
1 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert

How to Install Own Cloud On an an Ubuntu 18.04 Dedicated Server or VPS

You can create your own self-hosted cloud storage services by installing the ope
3 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Deploy Docker Containers with OpenStack Heat

This guide is written to help users deploy Docker containers using OpenStackHeat
5 min read
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How To Install the Vesta Control Panel on Ubuntu 18.04

How to install the Vesta control panel on Ubuntu 18.04
2 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top