Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 永久重定向htaccess到一个新域名,保持URL的一部分不变_Php_.htaccess_Redirect_Iis - Fatal编程技术网

Php 永久重定向htaccess到一个新域名,保持URL的一部分不变

Php 永久重定向htaccess到一个新域名,保持URL的一部分不变,php,.htaccess,redirect,iis,Php,.htaccess,Redirect,Iis,我从来没有写过任何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/targ

我从来没有写过任何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动态的,它代表我的目录中的所有文件


谢谢

您可以将其放入您的.htacces或虚拟主机中,如下所示

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

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

RewriteEngine On

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

哦,对不起,我没有提到它涉及许多文件,所以它必须是动态的,因为keep/this.ext是动态的。我会更新我的帖子。