.htaccess to redirect all URL to SSL excpet the one with “s” QueryString

I have a WordPress powered website and I am using following .htaccess code to redirect all URLs from HTTP to HTTPS

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Well, it is working fine! But now I need to redirect only one page with QueryString 's' to the non SSL (HTTP) one.
The structure of the URL is-

Read More

https://www.example.com/articles/?s={random_texts} (current)

and I want it to redirect to –

http://www.example.com/articles/?s={random_texts} (looking for)

Related posts

2 comments

  1. Thanks to starkeen after a little modification I figured out the problem. Here is the code which resolved the query-

    RewriteEngine On
    RewriteCond %{THE_REQUEST} !/articles/ [NC]
    RewriteCond %{QUERY_STRING} !s [NC]
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    RewriteCond %{THE_REQUEST} /articles/ [NC]
    RewriteCond %{QUERY_STRING} s [NC]
    RewriteCond %{HTTPS} on
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
  2. Try :

    RewriteEngine On
    RewriteCond %{THE_REQUEST} !/articles/?s=.+ [NC]
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    ##redirect /articles/?s=.+ from https to http##
    RewriteCond %{THE_REQUEST} /articles/?s=.+ [NC]
    RewriteCond %{HTTPS} on
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

    Clear your browser’s cache before testing this.

Comments are closed.