Home > Net >  How to redirect link of old domain to new domain?
How to redirect link of old domain to new domain?

Time:10-10

I transfer my client's CMS from a domain to another domain. I also change the directory where CMS was installed. CMS in old domain was installed in client's subdirectory and in new domain is in wwwroot. I would like not to make this migration difficult for customers and I thought of using an .htaccess file to be inserted in the root of the old domain to redirect to the new one. In particular, I would like if (for example) a customer clicks on a link sent to him via email from the CMS again when he was pointing to the old domain, he would be redirected to the same page as the new domain. For example, if in the customer's email there was a link such as

https://olddomain.example/clients/viewinvoice.php?id=447

will be redirected to

https://newdomain.example/viewinvoice.php?id=447

How could this be done? I tried with:

RewriteEngine On 

RewriteBase /
    
RewriteRule ^clients(.*)$ https://www.newdomain.example/$1 [L,R=301]

CodePudding user response:

RewriteEngine on

RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ clients/$1 [L]

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

Options -Indexes

CodePudding user response:

Solved like indicated from @example-person

RewriteEngine On 

RewriteBase /
    
RewriteRule ^clients(.*)$ https://www.newdomain.example/$1 [L,QSA,R=301]
  • Related