2017-12-30 24 views
1

MVCを使用する前に、この行を使用してURLをhttpsにしました。ユーザーがwww.example.comで入力したのであれば、それはしかしhttps://example.comMVCを使用してhttpsバージョンへのサイトポイントを作成する方法

RewriteRule (.*) https://example.com/$1 [R] 

にそれらを取るでしょう、で入力しwww.example.com、私のMVCのウェブサイトでこれをやろうとしたときにはそのURLに私を取り、 httpsにリダイレクトされません。手動でhttps://mexample.comと入力してhttpsバージョンに移動する必要があります。これをどうすれば解決できますか?私のルートで

は、私の.htaccessは次のようになります。

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteRule ^$ public/ [L] 
RewriteRule (.*) public/$1 [L] 
RewriteRule (.*) https://example.com/$1 [R] 
</IfModule> 

その後、私のパブリックフォルダ内の私の.htaccessは、次のようになります。

<IfModule mod_rewrite.c> 
Options -Multiviews 
RewriteEngine On 
RewriteBase /public 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] 
</IfModule> 

答えて

1

私は一般的に、私は好きなように.htaccessファイルでこれを行うことを避けます私はリバースプロキシとCloudflareを使用しているので、アプリサーバー間でend2end証明書を設定する必要があり、nginxやcaddyserverの代わりにapache2を使用することになります。

は、だから、僕は、たとえば、ベースコントローラにPHPでそれを行う:

// is https 
$https = false; 
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { 
    $https = true; 
} 
elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { 
    $https = true; 
} 

// is not https but required as https in config 
if (!$https && $this->f3->get('app.security.force_https') === true) { 
    exit(header('Location: '.$this->f3->get('site.url'), 302)); 
} 

あなたはhtaccessファイルでそれをしたい場合は、何かのように:

# ---------------------------------------------------------------------- 
# | Forcing `https://`             | 
# ---------------------------------------------------------------------- 

# Redirect from the `http://` to the `https://` version of the URL. 
# https://wiki.apache.org/httpd/RewriteHTTPToHTTPS 

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{HTTPS} !=on 
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] 
</IfModule> 
+0

素晴らしい、ありがとう! – user8463989

関連する問題