2014-10-18 109 views
0

我正在尋找將所有流量指向https://www.domain.co.uk。所以無論何時需要http://www.domain.co.uk,http://domain.co.uk或甚至https://domain.co.uk,它都會被重定向到https://www.domain.co.ukApache httpd - 將非www&http重定向到https:// www

我在使用httpd.conf中的虛擬主機嘗試實現這一點時遇到了困難。我曾嘗試以下(以及許多其他變化。

<VirtualHost *:80> 
    ServerName domain.co.uk 
    ServerAlias domain.co.uk 
    Redirect/https://www.domain.co.uk  
</VirtualHost> 

<VirtualHost *:443> 
     ServerAdmin [email protected] 
     ServerName domain.co.uk 
     ServerAlias www.domain.co.uk 
     DirectoryIndex index.html 
     DocumentRoot /var/www/html/domain.co.uk 
     SSLEngine on 
     SSLCertificateFile /etc/httpd/ssl/www.domain.co.uk.crt 
     SSLCertificateKeyFile /etc/httpd/ssl/www.domain.co.uk.key 
     SSLCertificateChainFile /etc/httpd/ssl/www.domain.co.uk-geotrust.crt 
     <Directory /var/www/html/domain.co.uk> 
      Options FollowSymLinks 
      AllowOverride all 
      Allow from all 
     </Directory> 
     DocumentRoot /var/www/html/domain.co.uk 
     ServerName domain.co.uk 
</VirtualHost> 

<VirtualHost *:443> 
     ServerAdmin [email protected] 
     ServerName domain.co.uk 
     ServerAlias *.domain.co.uk 

     <Directory /var/www/html/domain.co.uk> 
      Options FollowSymLinks 
      AllowOverride all 
      Allow from all 
     </Directory> 
     DocumentRoot /var/www/html/domain.co.uk 
</VirtualHost> 

使用上述設置,當我去http://domain.co.uk我得到一個403禁止響應。此外,參觀https://domain.co.uk時,它並不會因此重定向和我得到一個隱私錯誤在Chrome

如果你能幫助我實現我的目標,我將非常感激

謝謝

回答

0

可以在/var/www/html/domain.co.uk/.htaccess創建此規則:。

RewriteEngine On 
RewriteBase/

RewriteCond %{HTTPS} off [OR] 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
#RewriteRule^https://www.domain.co.uk%{REQUEST_URI} [R=301,L,NE] 
相關問題