[英]Auto load the website to Subfolder with HTTPS in .htaccess
我剛剛在服務器上安裝了SSL證書。
當前網址:www.example.com
當前工作的htaccess文件:
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule ^(.*)$ public/ [L]
它重定向到public / index.php。
但是問題是當我在htaccess中添加HTTPS代碼時,此public / index.php無法正常工作。
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?(.*) https://www.example.com/$1 [R]
當我刪除公共重定向部分時,HTTPS可以正常工作,但沒有指向public / index.php。
我如何結合這些規則,以便它將使用https url重定向到public / index.php。
PS:公共/ htaccess
ReWriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
請幫忙!
謝謝
您可以使用PHP重定向到HTTPS網站:
if(empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off"){
$redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirect);
exit();
}
發件人: 使用PHP從HTTP重定向到HTTPS
但是,此代碼段需要包含在每個頁面上,或包含在所有其他文件包含的PHP文件中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.