将大部分站点https重定向到除一个部分之外的http

时间:2015-01-06 10:03:41

标签: php regex apache .htaccess redirect

我有一个网站,我们只希望https在结算部分工作,因为这是目前唯一设置使用它的部分,因此我们要确保是否有人访问https在网站的其他部分,他们将被重定向到http等价物。

目前我们只对一个页面执行此操作,这是来自站点根目录的当前.htaccess文件:

RewriteEngine On

RewriteCond %{HTTPS} =on
RewriteRule ^auction_search.php$ http://%{HTTP_HOST}/auction_search.php [R=301,L]

RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]

RewriteRule ^(.*),(.*)$ $2.php?rewrite_params=$1&page_url=$2

RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR] 
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR] 
RewriteCond %{QUERY_STRING} GLOBALS(=|[|%[0-9A-Z]{0,2}) [OR] 
RewriteCond %{QUERY_STRING} _REQUEST(=|[|%[0-9A-Z]{0,2}) 
RewriteRule ^(.*)$ index.php [F,L]

RewriteRule ^stores/([0-9a-z.-]+)/?$ shop.php?shop_id=$1 [L,QSA,NC]
RewriteRule ^stores/([0-9a-z.-]+)/ajax_files/watch_item\.php$ ajax_files/watch_item.php [L,QSA,NC]
RewriteRule ^stores/([0-9a-z.-]+)/ajax_files/save_field\.php$ ajax_files/save_field.php [L,QSA,NC]
RewriteRule ^stores/([0-9a-z.-]+)/images/form-cb-icons\.png$ images/form-cb-icons.png [L,NC]

RewriteRule ^group-break/([0-9]+)/[0-9a-z.-]+/?$ group_break.php?cb_id=$1 [L,NC]
RewriteRule ^group-breaks/([a-z]+)-[a-z-]+/?$ group_breaks.php?tab=$1 [L,NC]

正如你在顶部附近看到的那样:

RewriteCond %{HTTPS} =on
RewriteRule ^auction_search.php$ http://%{HTTP_HOST}/auction_search.php [R=301,L]

因此,我们希望对此进行更改,以便将所有https个请求重定向到等效的http页面APART中的任何内容,并包含从主根运行的目录billing,即;它的位置是:www.mysite.com/billing/

修改:它实际上应该允许在https上查看以下扩展名:.png,.jpg,.jpeg,.gif,.css,.js

所以只是想知道我们如何改变当前的规则,我们必须做我们想做的事情?

1 个答案:

答案 0 :(得分:2)

您可以在同一个地方使用此规则:

RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !\.(jpe?g|gif|bmp|png|ico|js|css)$ [NC]
RewriteRule !^billing(/.*)?$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC,NE]