2

I have Drupal Site.

I have checked all the below links, but either they don't redirect or I gets an error- Site has too many redirects

I need to redirect my complete site HTTP to HTTPS except for two pages:-

  • Home - www.hello.com
  • Products - www.hello.com/products

The below code-snippet redirects complete site to HTTPS with no issue but I need to escape the Home & products page & for that I have tried about with more than 10-15 combinations.

   RewriteCond %{HTTPS} off [OR]
   RewriteCond %{HTTP_HOST} ^www.hello\.com*
   RewriteRule ^(.*)$ https://hello.com/$1 [L,R=301]

Any Help Highly appreciated.

Community
  • 1
  • 1
Kgn-web
  • 7,047
  • 24
  • 95
  • 161
  • Why not the whole site, including those two pages? – Mark Baker May 08 '16 at 10:13
  • 1)Home page is simple static page, so HTTP will load faster comparison to HTTPS – Kgn-web May 08 '16 at 10:15
  • 2)The Other page is making an external domain request so in HTTPS , it it blocked, & the user has to approve & then page reloads & then that request is served – Kgn-web May 08 '16 at 10:16
  • re 1.... except that the logic for identifying whether it should be https or not is also an overhead (compared with simply redirecting everything to https), so any negligeable speed benefit of not serving https for that one page is offset anyway – Mark Baker May 08 '16 at 10:26
  • re 2.... how is the external domain request being blocked in https? – Mark Baker May 08 '16 at 10:27
  • @MarkBaker re 2.. not sure but in the second page, map is loaded into iFrame for every product shop – Kgn-web May 08 '16 at 10:42
  • @MarkBaker, I am getting the below error https://support.schoology.com/hc/en-us/articles/201002223--This-page-is-trying-to-load-scripts-from-unauthenticated-sources-Error-Load-Unsafe-Scripts- – Kgn-web May 08 '16 at 11:19

2 Answers2

2

You can use:

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.hello\.com
RewriteCond %{REQUEST_URI} !^/products/?$ [NC]
RewriteRule ^(.+)$ https://hello.com/$1 [L,R=301]
Croises
  • 18,570
  • 4
  • 30
  • 47
0

Ok let's try with you , this is your code :

 RewriteCond %{HTTPS} off [OR]
 RewriteCond %{HTTP_HOST} ^www.hello\.com*
 RewriteRule ^(.*)$ https://hello.com/$1 [L,R=301]

change it to this :

RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www.hello\.com*
RewriteCond %{SCRIPT_FILENAME} !products [NC]
RewriteRule ^(.+)$ https://hello.com/$1 [L,R=301]

Please try it and let me know if not doing what you want.

Mohammed Elhag
  • 4,272
  • 1
  • 10
  • 18
  • nopes mate..redirects fine for home page but not with the products page and other pages , plus it appends a query string for every page other than home as `www.hello.com/index.php?q=products` – Kgn-web May 08 '16 at 17:09