简体   繁体   English

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

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

I have one domain abc.ca is already running & google crawled that url. 我有一个域abc.ca已经在运行,并且Google抓取了该网址。

Now i'm going for abc.com 现在我要去abc.com

so how can i manage all URL's of abc.ca -> abc.com 所以我该如何管理abc.ca-> abc.com的所有URL

using htacees. 使用htacees。 Site is built in PHP Joomla. 网站是用PHP Joomla构建的。

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

there are thousands of pages. 有数千页。 I can't write individual 301 redirection in htaccess. 我无法在htaccess中编写单个301重定向。

We can do this in PHP 我们可以用PHP做到这一点

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

It's better to do on PHP site or htaccess site? 最好在PHP网站或htaccess网站上进行?

You can try this: 您可以尝试以下方法:

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

I had simmilar issue but was cross domain one 我有类似的问题,但是是跨域的

Click Here 点击这里

I got solved my issue via this. 我通过这个解决了问题。

You can even do via cname entries in dns as its in your similar two domains. 您甚至可以通过dns中的cname条目来完成它,就像在您的两个相似域中一样。

I didn't test it but it should be like this: 我没有测试,但是应该是这样的:

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

else you might want to take a look at this question 否则你可能想看看这个问题

try this 尝试这个

<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]

Here you can modify RewriteBase / into your domain name. 在这里您可以将RewriteBase /修改为您的域名。 For sub domain you can give like this RewriteBase /subfolder 对于子域,您可以像这样RewriteBase /subfolder

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

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