[英]How to redirect a domain to another using .htaccess file
我最近從1&1
購買了一個域名,並將其托管在000webhost
。 我想將域重定向到另一個網站。 我嘗試使用
Redirect 301 / http://newsite.com/
但這沒有用。 有什么想法怎么辦?
我嘗試使用CPanel
的“重定向”按鈕,但這也沒有任何區別。
在其他任何事情之前,您的主機是否允許使用.htaccess
文件? 您是否有能力調整Web服務器配置以設置AllowOverride
以便可以使用.htaccess
文件? 示例配置設置如下所示:
<Directory "/var/www/oldsite.com/">
AllowOverride All
</Directory>
使用mod_rewrite
和一個RewriteRule
像這樣:
RewriteEngine on
RewriteRule ^(.*)$ http://newsite.com/$1 [L,R=301]
請注意, ^(.*)$
基本上捕獲了所有流量和參數。 然后將其重定向到http://newsite.com/
,然后$1
將參數傳遞到新站點。 因此,如果舊站點具有這樣的URL:
http://oldsite.com/category/item/thing
它將干凈地發送到:
http://newsite.com/category/item/thing
如果您不想這樣做,則可以像這樣忽略$1
:
RewriteEngine on
RewriteRule ^(.*)$ http://newsite.com/ [L,R=301]
因此,在第二個示例中,這樣的URL:
http://oldsite.com/category/item/thing
就像這樣轉到新站點的根目錄:
http://newsite.com/
另外,請注意, R=301
等於“ 301 Moved Permanently
。 如果這是臨時移動,則可以將其更改為R=302
以發送302 Moved Temporarily
臨時移動。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.