0

I know there are other pages out there that cover https to http but they all seem to mainly cover doing it for the whole site.

Basically what I'm trying to do is.... we have one section of our site that is served over https but in the header it includes a search field, this is currently pointed to http, but this is causing a warning icon in Chrome so we need to change it to https.

The search page it directs to is not setup to be served over https so we just want to redirect any https requests to that page to the http equivalent.

So for example:

https://www.example.com/search.php

gets redirected to:

http://www.example.com/search.php

...and:

https://www.example.com/search.php?term=foo&cat=bar

get redirected to:

http://www.example.com/search.php?term=foo&cat=bar

I was reading this page but still am not quite sure how to do it properly.

Also, not 100% sure where in my current .htaccess file to put it, this is our current file:

RewriteEngine On

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]

RewriteRule ^afltcc$ /register.php?partner_id=100 [L,NC]

Can it be put anywhere?

Brett
  • 19,449
  • 54
  • 157
  • 290

1 Answers1

1

You can use this rule to redirect request for (HTTPS) search.php to it's (HTTP) search.php along with all the query parameters in the request.

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

I would recommend placing this above all the non-redirectional rewrite rules on your .htaccess

kums
  • 2,661
  • 2
  • 13
  • 16
  • How does that do all the query parameters as well? I thought you needed to add in the `QSA` in there? – Brett Nov 01 '14 at 07:08
  • 2
    Query string is carried over **as is** to target URL if target has no `?` in it. `QSA` is not needed here. – anubhava Nov 01 '14 at 07:10
  • 1
    @Brett Not required. It is required only if you are adding new query parameters in the redirection. [Read this for more explanation](http://stackoverflow.com/a/26410477/2745300) – kums Nov 01 '14 at 07:13
  • Oh ok thanks guys. Also, last question - can you clarify a bit more where to place this? Not 100% sure where you meant. – Brett Nov 01 '14 at 07:31
  • 1
    Place it just below `RewriteEngine On` line. – anubhava Nov 01 '14 at 07:35