2016-11-10 8 views
0

.htaccessファイルについてよく分かりません。 CPanelアカウントを1つホストしているウェブサイトがいくつかあります。私は私の "メイン"サイトをpublic_htmlフォルダに直接格納したくないので、サブフォルダに移動して、このサブディレクトリからメインサイトを読み込むことができる.htaccess設定を見つけました。それは働いている。ルートフォルダのディレクトリを変更し、.htaccessを使用してHTTPSにリダイレクト

# .htaccess main domain to subdirectory redirect 
# Do not change this line. 
RewriteEngine on 
# Change example.com to be your main domain. 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteCond %{REQUEST_URI} !^/example_directory/ 
# Don't change the following two lines. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteRule ^(.*)$ /example.com/$1 
# Change example.com to be your main domain again. 
# Change 'subdirectory' to be the directory you will use for your main domain 
# followed by/then the main file for your site, index.php, index.html, etc. 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
RewriteRule ^(/)?$ example.com/index.html 

私が言ったように、上記の.htaccessを使用すると、自分のサイトのファイルをroot権限ではなく別のフォルダに保存することができます。しかし、今私はこのサイトのリダイレクトをhttpsに強制しています。私は本当に私が困っ一緒にこれらの2つの機能を統合することを抱えているの.htaccessファイルを理解していないことから、

Force Website to Use SSL

しかし:私はここで、このサイトを見つけました。これに関する助けがあれば大いに感謝します。ありがとう。

答えて

0

私はこれを自分で考え出したと確信しています。私はちょうど私の.htaccessファイルの最後にこれを加えなければなりませんでした。

RewriteCond %{HTTP_HOST} ^example\.com [NC] 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} 

そしてそれは魅力的です。完全な.htaccessファイルは、サイトのフォルダディレクトリを変更してからhttpsで強制的に変更するようなものです。

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
RewriteCond %{REQUEST_URI} !^/example_directory/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /example.com/$1 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
RewriteRule ^(/)?$ example.com/index.html 
RewriteCond %{HTTP_HOST} ^example\.com [NC] 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} 
関連する問題