我需要一个脚本来 .htaccess 来 301 重定向 http 到 https,但是一个页面需要通过 HTTP 访问。示例:
example.com/*
重定向到 https://example.com/*
example.com/page1
不重定向到 https://example.com/page1
最佳答案
只需使用这个:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
因此它只会将所有页面的 SSL 设置为 https,即使有人通过 http 访问它也是如此。
如果你想对目录/page1 以外的所有内容强制使用 https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !page1 [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
关于.htaccess - 将 HTTP 重定向到 HTTPS Htaccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37797082/