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

Php 如何从一个域重定向到另一个域?,php,.htaccess,Php,.htaccess,我有一个域名 abc.ca已经在运行&谷歌抓取了这个url 现在我要走了 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']; $

我有一个域名 abc.ca已经在运行&谷歌抓取了这个url

现在我要走了 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]

命令拒绝,允许
全盘否定
重写基/
重写规则^sitemap.xml$index.php?route=feed/google_sitemap[L]
重写规则^googlebase.xml$index.php?route=feed/google_base[L]
重写规则^download/(.*)/index.php?route=error/not_found[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写条件%{REQUEST\u URI}!。*\。(ico | gif | jpg | jpeg | png | js | css)
RewriteRule^([^?]*)index.php?_route_uu=$1[L,QSA]
在这里,您可以将
RewriteBase/
修改为您的域名。 对于子域,您可以这样给出
RewriteBase/subfolder