当从不安全的http://,向我的网站发出请求时,我希望它被重定向到https://.
我的根目录中有html和php文件。根据请求路径,我将决定是提供HTML文件还是PHP文件。
下面是我现有的.htaccess文件。
RewriteEngine On
RewriteRule "^(news_[^.]+|faq|terms|get).*" "$1.php" [NC,L]以上配置可以很好地为来自安全域和不安全域的文件提供服务。
但是,当我试图通过更改上面的配置来强制SSL时
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on
# # Redirect to https version
RewriteRule ^get$ "https://example.com/get.php" [L]
RewriteRule ^faq$ "https://example.com/faq.php" [L]
RewriteRule ^terms$ "https://example.com/terms.php" [L]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]它强制对从目录中服务的所有html页面使用SSL。但是/get,/faq,/terms正在获得请求超时。
我该怎么解决呢?我在哪里做错了?
发布于 2018-01-12 01:09:44
RewriteEngine On
### WWW & HTTPS# ensure www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
### WWW & HTTPS这样就行了。编辑您的.htaccess以反映相同的内容,并将其放置在根中。
https://stackoverflow.com/questions/48217940
复制相似问题