0

我不是最擅长的,但我必须做一个重定向

domain1.tld/subfolder/seo/based/uri

我需要重定向到

subd.domain2.tld/seo/based/uri

那可能吗?

编辑:

忘了提,这些都是动态请求。喜欢:

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

3 回答 3

0

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

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

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

更多信息在这里: http: //php.net/manual/en/function.header.php

于 2012-09-21T16:30:17.703 回答
0

在 htaccess 文件或 domain1.tld 的虚拟主机中,添加:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain1.tld$ [NC]
RewriteRule ^/?subfolder/(.*) http://subd.domain2.tld/$1 [L,R=301]

如果 2 个主机具有不同的文档根,您也可以使用 mod_alias:

Redirect 301 /subfolder http://subd.domain2.tld
于 2012-09-21T21:58:59.280 回答
0

从 .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 的答案,因为这将更接近您想要的。

于 2012-09-21T16:38:00.663 回答