如何使htaccess在表单提交时不redirect到http

部分.htaccess文件在某些​​页面上强制https (例如,当用户login时,input信用卡信息等),同时在所有其他页面上强制http 。 这似乎是我需要的理想设置。

但是,我的网站的其中一个分机负责生成信用卡处理表单。 在表单的动作url中,它包含了web根目录的https url(例如https://domain.com/ )。 但是,web根目录不是.htaccess强制https页面之一,因此它强制redirecthttp 。 正因为如此,该扩展失败,因为该表单正试图提交到一个httpsredirect到http

我该怎么办? 我不希望用户在不需要时查看受保护的页面; 我宁愿他们收获caching的好处。 显然,在受保护的页面上,他们需要提交到安全的URL(我的网站的CMS显然是这样工作的,所有表单提交到web根目录工作得很好)。 我无法告诉扩展程序提交到不同的URL。

以下是我的.htaccess的相关部分:

 <IfModule mod_rewrite.c> RewriteEngine On # Define default protocol for all assets RewriteRule ^ - [E=protocol:http,E=ssl:%{HTTPS}off] # Define HTTPS targets, add more cond as required RewriteCond $1 (payment|sign-in|sign-up) [NC] RewriteRule (.*) - [E=protocol:https,E=ssl:%{HTTPS}on] # Rewrite host if necessary and redirect on correct protocol RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^ %{ENV:protocol}://%1%{REQUEST_URI} [L,R=301] # Protocol switch if necessary (host is already correct) RewriteCond %{ENV:ssl} ^(onoff|offon) RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$ [NC] RewriteRule ^ %{ENV:protocol}://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Finally, process the internal redirect RewriteCond $1 !\.(gif|jpe?g|png)$ [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/$1 [L] </IfModule> 

也许这可以修改为“如果是表单提交,不要redirect?”

在我看来,您通过严格强制某些页面使用HTTPS和其他使用普通HTTP来优化错误的东西。 只需将所有内容redirect到HTTPS,然后完成。

在大多数情况下,HTTPS的计算成本可以忽略不计。
您对SSL的浏览器caching的担忧似乎也是没有根据的 。

还有我的宠儿:根据手册的说法,最好把主机的configuration文件放在主要的httpd.conf中,而不要依赖.htaccess文件。