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

vlurs2pr  于 2022-11-16  发布在  其他
关注(0)|答案(2)|浏览(150)

我将客户端的CMS从一个域转移到另一个域。我还更改了CMS的安装目录。旧域中的CMS安装在客户端的子目录中,而新域中的CMS安装在wwwroot中。我不想让客户难以进行此迁移,因此我想到使用.htaccess文件插入到旧域的根目录中,以重定向到新域。特别是,我希望(例如)当客户指向旧域名时,如果再次点击CMS通过电子邮件发送给他的链接,他将被重定向到新域名的同一页面。例如,如果客户的电子邮件中有一个链接,如

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

将被重定向到

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

这是怎么做到的呢?我试过:

RewriteEngine On 

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

ma8fv8wu1#

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
uelo1irk

uelo1irk2#

如@example-person所示解决

RewriteEngine On 

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

相关问题