2016-07-14 26 views
0

所有情況下正常工作時,重定向的https // example.com至https://www.example.com它保持不變https://example.com重定向HTTPS // example.com到https://www.example.com -opencart v 2.2.0.0

除我已經嘗試了這個論壇中的大部分解決方案,但沒有爲我工作 - 我的證書適用於「www.example.com」和example.com域。 - 我修改了修爲url.php

-htaccess:(我曾嘗試在這裏不同的解決方案)

RewriteEngine On 

RewriteCond %{HTTP_HOST} !^www\. [NC,OR] 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] 
RewriteRule^https://www.%1%{REQUEST_URI} [R=302,L,NE] 

管理/ config.php文件

// HTTP 
define('HTTP_SERVER', 'https://www.example.com/admin/'); 
define('HTTP_CATALOG', 'https://www.example.com/'); 

// HTTPS 
define('HTTPS_SERVER', 'https://www.example.com/admin/'); 
define('HTTPS_CATALOG', 'https://www.example.com/'); 

的config.php

// HTTP 
define('HTTP_SERVER', 'https://www.example.com/'); 

// HTTPS 
define('HTTPS_SERVER', 'https://www.example.com/'); 

000-default.conf

<VirtualHost *:80> 

    ServerAdmin [email protected] 
    ServerName www.example.com 
    ServerAlias example.com 
    DocumentRoot /var/www/html 

    ErrorLog ${APACHE_LOG_DIR}/error.log 
    CustomLog ${APACHE_LOG_DIR}/access.log combined 

    <Directory /var/www/html> 
      Options Indexes FollowSymLinks MultiViews 
      AllowOverride All 
      Order allow,deny 
      allow from all 
    </Directory> 
</VirtualHost> 

您的幫助表示讚賞。

回答

0

下面的代碼會將yourdomain.com的所有請求重定向到www.yourdomain.com。這可以通過添加在.htaccess文件的開頭以下行中您的public_html文件夾來完成:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC] 
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301] 

或者

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC] 
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301] 

請檢查 - reference

希望這有助於你。

+0

它不適用於這種情況https://example.com。它會保持不變 – momoPro

+0

請檢查鏈接http://stackoverflow.com/questions/2830801/problem-with-redirecting-example-com-example-com-to-www-example-com-for-http?rq= 1 – Monika

相關問題