Htaccess HTTPS redirection



我正试图让我的.htaccess文件只将某些页面/文件夹重定向到https,如果不是需要加密的页面,那么它应该向用户发送http页面。此外,我希望能够列出某些文件夹,可以是HTTP或HTTPS

以下是我自己写的东西。但似乎并不能完全正常工作。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteCond $1 ^(myaccount|payment.html)
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
RewriteCond %{SERVER_PORT} 443
RewriteCond $1 !^(myaccount|payment.html)
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
</IfModule>

您正在检查RewriteCond模式中的文字$1。应该是:

RewriteCond %{REQUEST_URI} ...stuff to match against here...

这应该是您想要的。

RewriteCond %{SERVER_PORT} 443 [NC]
RewriteCond %{REQUEST_URI} !^/(myaccount|payment).html [NC]
RewriteRule . http://www.domain.com/%{REQUEST_URI}/ [R=301,L]

最新更新