0

I have these vales in my htacces file it all works fine except when i try to go back to http from https i have tried swapping the rules around with no success, any help would be awsome

I have tried all the sujestion with still no suucess so maybe i need to show you guys the entire thing.

Still not going back to http from https, here is the whole thing Have i got the rules in the wrong order? im lost

<ifModule mod_rewrite.c>
RewriteEngine on
# For Sales:

RewriteRule ^shop/sales/?$ sales.php
# For the primary categories:

RewriteRule ^shop/([A-Z-Aa-z\+]+)/?$ shop.php?type=$1
# For specific products:

RewriteRule ^browse/([A-Za-z\+]+)/([A-Za-z\+\-]+)/([0-9]+)$ browse.php?type=$1&category=$2&id=$3
#For https pages:

#RewriteCond %{HTTPS} on
#RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L=301]

#RewriteCond %{HTTPS} off
#RewriteRule ^(checkout\.php|final\.php|admin/(.*))$ https://{HTTP_HOST}/$1[R=301,L]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ /%1 [R=301,L]
</ifModule>
4

1 回答 1

0

我无法测试规则,但我认为您需要更改以下内容:

在第一条规则中,您的标志附加到第二个参数。这应该会产生内部错误。您的第二条规则会将所有 url 重写为它们的 http 等效项,从而形成无限循环。您需要确保它与您希望在 https 中的 url 不匹配。您可以使用%{REQUEST_URI}和 否定 ( !) 来执行此操作。据我所知,L=301也是一个无效标志。你可能打算成功了R=301

RewriteCond %{HTTPS} off
RewriteRule ^(checkout\.php|final\.php|admin/(.*))$ https://{HTTP_HOST}/$1 [R,L]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !/(checkout\.php|final\.php|admin/(.*))$
RewriteRule ^http://%{HTTP_HOST}%{REQUEST_URI} [R,L]

最后但并非最不重要的忠告。.htaccess在一切按预期工作之前,不要使用永久重定向来测试您的。浏览器将缓存永久重定向,而不是进一步尝试使您的.htaccess工作随心所欲。

于 2013-08-28T12:33:59.563 回答