简体   繁体   English

如何将旧域的链接重定向到新域?

[英]How to redirect link of old domain to new domain?

I transfer my client's CMS from a domain to another domain.我将客户的 CMS 从一个域转移到另一个域。 I also change the directory where CMS was installed.我还更改了安装 CMS 的目录。 CMS in old domain was installed in client's subdirectory and in new domain is in wwwroot.旧域中的 CMS 安装在客户端的子目录中,新域中的 CMS 位于 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.我不想让客户的迁移变得困难,我想到了使用.htaccess文件插入旧域的根目录以重定向到新域。 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.特别是,如果(例如)客户在指向旧域时再次单击 CMS 通过 email 发送给他的链接,他将被重定向到与新域相同的页面。 For example, if in the customer's email there was a link such as例如,如果在客户的 email 中有一个链接,例如

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]
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

Solved like indicated from @example-person按照@example-person 的指示解决

RewriteEngine On 

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM