簡體   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