2016-06-14 157 views
0

我試圖重定向我們的舊網站從http到https和從非www到www在同一時間。我們目前有很多鏈接,這些年來我們通過網站的非www版本&獲得了很多鏈接,並且我想減少重定向量,因爲不想被「鏈接果汁」所稀釋。我們也有從https //非www鏈接和http // WWW:/從非www的http重定向到https與www

目前重定向模式是這樣的:

HTTP://domain.com/oldpage.html
301移到永久
的https://domain.com/oldpage.html
301永久移動
的https://www.domain.com/newpage.html
200 OK

是否有解決方法讓301重定向更少? 例如是這樣的:
HTTP // domain.com/oldpage.html - >到https://www.domain.com/newpage.html

+0

當然,這是完全可能的。 – ceejayoz

回答

0

是,很容易理解在匹配首選形式是

該請求的任何URL 運行的正則表達式

https://www

像在JavaScript /^https:\/\/www\..*$/.exec(url) 如果返回非零值 這就是意味着URL folow中的HTTPS & WWW形式

否則,如果他們中的一個vaiolats你的規則,如HTTP或非WWW網址或全部 解析URL,並提取路徑纔將其附加到你的完美網址

var redirectURL = "https://www.yourDomain.com"+path; 

,然後發送重定向請求到這個完美的形式。

從這個請求

http://yourDomain.com/something

重定向到新的URL

https://www.yourDomain.com/something

只是一個重定向響應

+0

非常感謝你們倆。這也可以從另一個.domain工作嗎?我們有另一個使用另一個域名結尾的組級別網站。我們希望通過一次重定向將某些頁面傳遞到當前網站。 這是否意味着我們可以在組網站上使用這樣的設置。 ServerName domain.a ServerAlias www.domain.a 重定向永久/ https://www.domain.b 然後在站點b上指定組url。用一個簡單的。 重定向301/old-page/https://www.domain.b/new-page/ – pukander

+0

更簡單的方法是:在.a域中,您想要重定向的已知頁面只需提取路徑並將其附加到完美前綴「https://www.domain.b」+路徑並要求重定向到這個完美的URL,即使您可以將路徑更改爲.b服務器中的相應路徑(如果它不同 –

0
NameVirtualHost *:80 
    <VirtualHost *:80> 
    ServerName example.com 
    ServerAlias www.example.com 
    RedirectPermanent/https://www.example.com 
    </VirtualHost> 

    <VirtualHost *:80> 
    ServerName example.net 
    ServerAlias www.example.net 
    DocumentRoot /var/www/html/example.net 
    RedirectMatch "old-page$" "https://www.example.com/new-page」 
    </VirtualHost> 

    <VirtualHost *:443> 
    ServerName www.example.com 
    ... 
    </VirtualHost> 

編號:https://wiki.apache.org/httpd/RedirectSSL

0

這是你想要在你.htaccess

只有1個重定向什麼,如果不管它是不安全的(HTTP),頂(WWW-以下)或兩者:

# canonical redirect http → https (with optional www complection) 
RewriteCond %{HTTPS} !=on 
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC] 
RewriteRule ^/?(.*) https://www.example.com/$1 [L,R=301] 

# https:// apex → https:// www.* 
RewriteCond %{HTTP_HOST} ^(?!www\.)example.com [NC] 
RewriteRule ^/?(.*) https://www.example.com/$1 [L,R=301]