如何从一个域重定向到另一个域?

时间:2013-08-05 07:29:22

标签: php .htaccess

我有一个域名 abc.ca已经在运行&谷歌抓了那个网址。

现在我要去了 abc.com

那么如何管理abc.ca的所有网址 - > abc.com

使用htacees。网站是用PHP Joomla构建的。

abc.ca/def.html - > abc.com/def.html

有数千页。我无法在htaccess中编写单独的301重定向。

我们可以在PHP中执行此操作

$uri =  "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$newUrl = str_replace(".ca", ".com", $uri);
header("Location: " . $newUrl);

最好在PHP网站或htaccess网站上做什么?

4 个答案:

答案 0 :(得分:1)

你可以试试这个:

RewriteCond %{HTTP_HOST} !^www\.abc.\.com
RewriteRule ^(.*)$ http://www.abc.com/$1 [R=permanent,L]

答案 1 :(得分:0)

我有类似的问题但是是跨域的

Click Here

我通过这个解决了我的问题。

您甚至可以通过dns中的cname条目在您的类似的两个域中进行操作。

答案 2 :(得分:0)

我没有测试它,但它应该是这样的:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^abc.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.abc.ca$
RewriteRule (.*)$ http://www.abc.com/$1 [R=301,L]

Redirect 301 /old/old.htm http://www.domain.com/new.htm

否则您可能需要查看此question

答案 3 :(得分:0)

试试这个

<FilesMatch "\.(tpl|ini|log)">
 Order deny,allow
 Deny from all
</FilesMatch>
    RewriteBase /
    RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
    RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
    RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
    RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

您可以在此处将 RewriteBase / 修改为您的域名。 对于子域名,您可以像这样 RewriteBase /subfolder

相关问题