我正在努力实现以下目标:
将所有WWW请求重定向到等效(无WWW)
将所有HTTPS请求重定向到HTTP
将所有请求重定向到子目录/购物车强制HTTPS
这是我所拥有的,但它给了我一个循环。
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(cart/.*)$ https://example.com/$1 [R,L]
RewriteRule ^(.*)$ http://example.com/$1 [R,L]
答案 0 :(得分:1)
RewriteEngine On
#www to non-www
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://example.com/$1 [R,L]
#https to http
RewriteCond %{HTTPS} ^on$
RewriteRule ^(.*)$ http://example.com/$1 [R,L]
#if the request is for /cart then enable https
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/cart
RewriteRule ^(.*)$ https://example.com/$1 [R,L]