繁体   English   中英

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

[英]How to redirect from one domain to another?

我有一个域abc.ca已经在运行,并且Google抓取了该网址。

现在我要去abc.com

所以我该如何管理abc.ca-> abc.com的所有URL

使用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网站上进行?

您可以尝试以下方法:

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

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

点击这里

我通过这个解决了问题。

您甚至可以通过dns中的cname条目来完成它,就像在您的两个相似域中一样。

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

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

否则你可能想看看这个问题

尝试这个

<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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM