我正在尝试为每个 URL 强制执行 SSL,但第一个段除外/preview
。
http://test.example.com/preview/blah/blah
Run Code Online (Sandbox Code Playgroud)
应该被规则忽略;应该强制所有其他 URL 使用 SSL。我正在使用 CentOS 6.4、Apache 和 CodeIgniter。
我的 .htaccess 文件:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/preview/
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Run Code Online (Sandbox Code Playgroud)
通常 CI URL 在被最后一条规则重写之前看起来像这样:
http://test.example.com/index.php?/preview/blah/blah
Run Code Online (Sandbox Code Playgroud)
我试过了:
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/index.php?/preview/
RewriteCond %{REQUEST_URI} !^/preview/
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Run Code Online (Sandbox Code Playgroud)
那也行不通。我究竟做错了什么?