我刚开始使用.htaccess,我在网上做了不少搜索工作,尝试了无数的“解决方案”来解决我的问题,但似乎没有人能做到这一点。
这里是我需要的:我希望使用安全连接下载我的contact.html页面(因此,表单提交将发送所有安全加密的凭据,等等)。我使用.htaccess完成了这一任务,没有出现使用以下代码的问题:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^contact\.html$
RewriteRule ^(.*)$ https://beta.runtimeriot.com/contact/$1 [R=301,L]因此,当用户导航到该contact.html页面时,将使用安全连接。效果很好。我只想使用一个安全连接来下载该页面,当然也可以将加密的用户信息发送回服务器。但是,一旦建立了安全连接以获取contact.html文件,则从该点开始的所有其他文件都将通过安全连接下载。例如,我导航到联系人页面,然后从那里跳转(单击链接)到about.html页面,仍然使用安全连接。我尝试过许多不同的方案来改变协议,从https到http,例如:
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^contact\.html$
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]但它们都不管用。我不完全理解使用.htaccess的所有功能(和限制),所以有人能告诉我,我的目标是否可以使用.htaccess来完成,还是需要寻找替代方案?
谢谢你的帮助!
更新1
下面是我的根.htaccess文件的全部代码。注:自上一篇文章以来,我修改了代码。
RewriteEngine On
Options FollowSymLinks
RewriteCond %{REQUEST_URI} !^/contact/contact\.html$
RewriteCond %{HTTPS} on
RewriteRule ^(.*) http://beta.runtimeriot.com/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(/contact/contact\.html)$ https://beta.runtimeriot.com/$1 [R=301,L]发布于 2011-10-13 03:27:10
实际上,我感到惊讶的是,您的第1条规则能够工作,因为REQUEST_URI变量通常包含领先的/,所以您的规则应该是:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/contact\.html$
RewriteRule ^(.*)$ https://beta.runtimeriot.com/contact/$1 [R=301,L]虽然我猜你是说:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/contact/contact\.html$
RewriteRule ^(.*)$ https://beta.runtimeriot.com/contact/$1 [R=301,L]或者,为了简单起见:
RewriteCond %{HTTPS} off
RewriteRule ^/contact/contact\.html https://beta.runtimeriot.com/$1 [R=301,L]第二个规则看起来很实用,但是它可能会创建一个无穷循环,因为它也是由/contact/contact.html匹配的。应:
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/contact/contact\.html$
RewriteRule (.*) http://%{HTTP_HOST}$1 [R=301,L]最后,我认为您的问题是您很困惑,第一条规则也不起作用(我实际上测试了http://beta.runtimeriot.com/contact.html,它没有交换到https)。可能的原因:
RewriteEngine on启用重写引擎了吗?(请参阅:http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriteengine)AllowOverride FileInfo或AllowOverride ALL,以便RewriteEngine on在.htaccess文件?中是可接受的)。
https://stackoverflow.com/questions/7748595
复制相似问题