【问题标题】:How to redirect domain path to other domain path using .htaccess?如何使用 .htaccess 将域路径重定向到其他域路径?
【发布时间】:2021-04-23 11:04:49
【问题描述】:

以下域只是示例域。 我想将 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

我该怎么做?谢谢

【问题讨论】:

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


    【解决方案1】:

    您能否尝试以下,用所示示例编写。请确保在测试您的 URL 之前清除您的浏览器缓存。

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

    【讨论】:

    • @Cyber​​licious,你能告诉我你点击的链接是什么吗?如果您也看到任何错误等,请务必提及。
    • @Cyber​​licious,此规则查找 URI 是否从 test 开始,然后进行重定向。所以它会像这里显示的示例一样重定向:http://localhost:80/test/singh123 TO https://google.com/dl/singh123
    • 谢谢,现在可以使用了。我只是忘了删除旧的 htaccess 规则。非常感谢!
    • @Cyber​​licious,欢迎您在这个伟大的论坛上欢呼,祝您学习愉快:)
    【解决方案2】:

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

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

    【讨论】:

    • 这不是对实际问题的回答。
    猜你喜欢
    • 2018-07-10
    • 2019-07-16
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 2013-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多