【问题标题】:Permanent redirect htaccess to a new domaine keeping a part of the URL as it is永久重定向 htaccess 到一个新的域,保持 URL 的一部分不变
【发布时间】:2018-02-19 21:58:16
【问题描述】:

我从来没有写过任何 htaccess 密码,而且默认情况下没有给我足够的工作来获得我需要的东西,

我有一个类似的网址:http://domaineA.com/target:/to/be/removed/keep/this.ext

我想将所有像这样的 URL 重定向到:

http://domaineB.com/keep/this.ext

我试过了,但没有用:

//301 Redirect Entire Directory
RedirectMatch 301 http://domaineA.com/target:/to/be/removed(.*) http://domaineB.com/$1

更新:

我忘了说 /keep/this.ext动态的,它代表了我的目录的所有文件

谢谢

【问题讨论】:

    标签: php .htaccess redirect iis


    【解决方案1】:

    你可以把它放在你的 .htacces 或你的虚拟主机中,如下所示

    Redirect permanent http://domaineA.com/target:/to/be/removed/keep/this.ext http://domaineB.com/keep/this.ext
    

    【讨论】:

    • 抱歉,我没有提到它涉及很多文件,所以它必须是动态的,因为 keep/this.ext 是动态的。我会更新我的帖子。
    【解决方案2】:

    您可以将此规则用作站点根目录 .htaccess 中的第一条规则:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(?:www\.)?domaineA\.com$ [NC]
    RewriteRule ^/?target:/to/be/removed(/.*)?$ http://domaineB.com$1 [L,NE,R=301,NC]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-13
      相关资源
      最近更新 更多