如何使用 .htaccess 将域路径重定向到其他域路径?

时间:2021-01-19 06:38:09

标签: .htaccess redirect mod-rewrite url-rewriting http-status-code-301

以下域只是示例域。 我想将 mydomain.com/test/(通配符)重定向到 google.com/dl(通配符)

我正在使用此代码

RewriteEngine on
RedirectMatch 301 ^/test/.*$ https://google.com/dl

但是当我访问 https://example.com/test/hi 时它重定向到 https://google.com/dl ,而不是 https://google.com/dl/hi

我该怎么做?谢谢

2 个答案:

答案 0 :(得分:2)

你能不能试试下面的,用显示的样本写的。在测试您的网址之前,请务必清除浏览器缓存。

RewriteEngine on
RewriteRule ^test/(.*)/?$ https://google.com/dl/$1 [R=301,NC,L]

答案 1 :(得分:-1)

你可以试试,你会找到100%的解决方案,你必须在项目的根文件夹.htaccess文件中添加以下3行

RewriteEngine on
RewriteBase /
RewriteRule (.*) http://www.new-domain.com/$1 [R=301,L][/php]