Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.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 uri重定向与域更改_Php_Apache_.htaccess_Redirect_Apache2 - Fatal编程技术网

Php uri重定向与域更改

Php uri重定向与域更改,php,apache,.htaccess,redirect,apache2,Php,Apache,.htaccess,Redirect,Apache2,我在这方面不是最好的,但我必须做一个重定向 domain1.tld/subfolder/seo/based/uri 我需要重定向到 subd.domain2.tld/seo/based/uri 可能吗 编辑: 忘了提一下,这些都是动态请求。比如: domain1.tld/forums/forum/2-network-announcements/topic-name-with-id 这可以在.htaccess或PHP中完成,但我发现在PHP中更容易实现 为此,第一个URL的PHP文件应包含:

我在这方面不是最好的,但我必须做一个重定向

domain1.tld/subfolder/seo/based/uri
我需要重定向到

subd.domain2.tld/seo/based/uri
可能吗

编辑:

忘了提一下,这些都是动态请求。比如:

domain1.tld/forums/forum/2-network-announcements/topic-name-with-id

这可以在.htaccess或PHP中完成,但我发现在PHP中更容易实现

为此,第一个URL的PHP文件应包含:

<?php
    header("Location: http://subd.domain2.tld/seo/based/uri");
?>


此处的更多信息:

从重定向。htaccess是即时的。也就是说,如果从.htaccess重定向,则不会在domain1.tld/subfolder/seo/based/uri处运行任何代码。如果这是您想要的,请将以下行添加到.htaccess中:

RewriteEngine On
RewriteRule ^domain1.tld/subfolder/(.*)$ subd.domain2.tld/$1

如果您确实想在domain1.tld/subfolder/seo/based/uri上运行一些代码,那么请阅读@tomtheman5的答案,因为这将更接近您想要的内容。

在htaccess文件或domain1.tld的vhost中,添加:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain1.tld$ [NC]
RewriteRule ^/?subfolder/(.*) http://subd.domain2.tld/$1 [L,R=301]
如果两台主机具有不同的文档根,您也可以使用mod_别名:

Redirect 301 /subfolder http://subd.domain2.tld