.htaccess 如何将http重定向到https

.htaccess 如何将http重定向到https,.htaccess,redirect,.htaccess,Redirect,我的.htaccess文件中有这个 RewriteEngine on # #Sub-dir e.g: /cmsms RewriteBase / # 301 Redirect all requests that don't contain a dot or trailing slash to # include a trailing slash # but ignore POST requests. #RewriteCond %{REQUEST_URI} !/$ #RewriteCond

我的.htaccess文件中有这个

    RewriteEngine on
#
#Sub-dir e.g: /cmsms
RewriteBase /

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
# but ignore POST requests.
#RewriteCond %{REQUEST_URI} !/$
#RewriteCond %{REQUEST_URI} !\.
#RewriteCond %{REQUEST_METHOD} !POST$
#RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]


# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
如何将我的网站从http重定向到https,并避免index.php?page=来自页面?

您可以执行以下操作:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]