无法在HTTP模式下访问某些目录

时间:2015-03-04 19:46:08

标签: apache .htaccess mod-rewrite rewrite

我有一个网站,我试图在HTTPS中运行,但某些目录除外。我在.htaccess中的命令会自动将站点放入HTTPS,但我的/ search和/ search-results不会重定向到HTTP。

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} on
RewriteRule ^search$ http://www.example.com/search [R=301,L]
RewriteRule ^search-results$ http://www.example.com/search-results [R=301,L]

有人可以告诉我正确的语法吗?

1 个答案:

答案 0 :(得分:0)

以这种方式试试。

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/(search|search-results)$ [NC]
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/(search|search-results)$ [NC]
RewriteRule ^ http://www.example.com/%1 [R=301,L]