重定向https异常

时间:2014-02-25 17:32:17

标签: .htaccess mod-rewrite

我目前正在使用.htaccess强制https在我网站的所有页面上,它可以正常工作。但是,当在cmd行中创建http(而不是https)curl请求时,由于此重写规则,我得到了“页面已移动”响应。我需要让脚本响应这样的事情:"error": { "message" : "This API is only accessible over HTTPS ...这意味着普通的http请求需要点击脚本。如何修改此.htaccess文件以允许对http://examplesite.com/api/index进行纯HTTP访问?

RewriteCond     %{SERVER_PORT} ^80$
RewriteRule     ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

2 个答案:

答案 0 :(得分:1)

您可以使用以下两条规则:

RewriteEngine On

RewriteCond     %{SERVER_PORT} ^80$
RewriteRule     !^api/index https://%{SERVER_NAME}%{REQUEST_URI} [L,NC,R=301]

RewriteCond     %{SERVER_PORT} ^443$
RewriteRule     ^api/index http://%{SERVER_NAME}%{REQUEST_URI} [L,NC,R=301]

答案 1 :(得分:1)

你可以尝试

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/api
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]