How to Redirect a Domain without Changing the URL

Redirect a Domain

Redirect a domain is a method that redirects a website to another website when visiting a web page. When you move your website to a new domain, you must redirect its pages. Frequently, you will need to redirect your web pages to a new domain without changing their URLs.

Here is the guide that helps you how to redirect your existing domain to another domain without affecting the website’s URL. It allows the user to display similar website information without changing the URL of the website. Let’s take a look at the methods below to allow domain redirection without modifying the URL.

Step to Redirect a Domain Without Changing the URL

Here are the steps to redirect the domain without changing the URL.

Step 1: Log in to your cPanel using your credentials and Locate File Manager. Click File Manager.

Redirect a Domain Without Changing URL

Step 2: Open the .htaccess file located in the public_html directory.

Domain Without Changing URL

Step 3:  Right-click the .htaccess file and click on Edit.
It will show up in the Edit pop-up. Click on the 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.

Redirect a Domain

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 webserver 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 to the .htaccess file.

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

What is a URL Redirect?

When you redirect a URL, you are simply directing it to another address on the same or a different domain. You can configure a redirect that directs visitors to your new domain name when they attempt to access a URL that was previously associated with your old domain.

Why Do I Need to Redirect My Website?

There are plenty of situations where redirecting a domain or URL can be useful. The most common reasons are:

  • Having duplicate content: Multiple posts that contain the same content can negatively impact SEO. Search engines can’t decide which URL is the correct one and which one to rank on the SERP.
  • Managing multiple domains: Instead of using multiple domains to display the same page, you can instead redirect them to the main one.
  • Migrating to a new domain: Again, you can permanently redirect an old domain to a new one by using a 301 redirect type. This carries over Google PageRank and other SEO factors like page authority.
  • Changing a post’s URL You can avoid the 404 error by redirecting any deleted page URLs to a new one.

People’s Frequently Asked Questions

Can I use DNS to redirect URL?

You can change a domain name’s DNS record to link to a different website address to set up URL forwarding. The DNS redirects individuals to the new URL when they access the old URL. There are 2 types of URL redirection: permanent and temporary.

How do I redirect an existing URL?

We recommend that you keep the field Type set to Permanent (301). Select the domain name you want to redirect to after that. Our source URL, for instance, is http://example.com/yourproduct.html. Put the information for the destination URL under Redirects to.

What is a permanent redirect from one URL to another?

Since 302 redirects are merely temporary, 301 redirects are permanent. A 302 should be used if you intend to relocate the page back under the old URL in the future rather than a 301 when it has been moved permanently. You should often make use of 301 redirects on your website.

More information

For more information about DNS and domains, check out these F60 Host resources: