【发布时间】:2013-12-27 06:54:09
【问题描述】:
我想用 Zend Framework 将所有 URL 重写为 SSL,但特定文件夹/控制器除外。例如,我想从 SSL 中排除身份验证控制器,然后如果我访问https://blabla.com/auth,我想重写为http://blabla.com/auth。
我在htaccess https redirect only on specific Zend Frameworks controller/actions 和Rewrite all URL to SSL except specific folders with Zend Framework 中尝试了一些代码,但没有任何效果。
现在这是我在 .htaccess 文件中的代码。有什么建议吗?
RewriteEngine On
RewriteCond %{HTTPS} on [NC]
RewriteCond %{REQUEST_URI} !^/(auth|client)/ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTPS} off [NC]
RewriteCond %{REQUEST_URI} ^/(auth|client)/ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [L]
更新
它不会引发任何错误,但是当我使用 http 访问页面时,它会将我重定向到使用 https 的索引页面:
RewriteEngine On
#If HTTPS is off and this is not /auth or /client - redirect to https
RewriteCond %{HTTPS} off
RewriteCond $1 !^(en/x/auth/index) [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
#If HTTPS is off and this is /auth or /client - redirect to http
RewriteCond %{HTTPS} on
RewriteCond $1 ^(en/x/auth/index) [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
【问题讨论】:
-
验证时不使用加密有意义吗?
-
使用你的 apache/virtualhost 配置文件。
-
是的,斯文,这没有意义,但我只是一个例子
标签: php .htaccess zend-framework ssl https