1

I currently have a SSL certificate applied to my site and ALL URLs redirect to https correctly. I need one of the URLS to be HTTP. I have the following code in my .htaccess that redirects all pages to HTTPS.

I would like the following URL below to be HTTP and NOT HTTPS.

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

RewriteEngine on
RewriteBase /
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Thanks in advance for your assistance!

jww
  • 97,681
  • 90
  • 411
  • 885
  • `RewriteRule ^blog_rss.php etc...`? – Marc B Aug 22 '14 at 21:47
  • Can you please clarify? – David Friedman Aug 22 '14 at 21:49
  • your rule matches everything. mine only matches if the requested url is blog_rss.php. And for such a simple redirect, you don't need to use mod_rewrite. a simple `Redirect Permanent /blog_rss.php http://etc...` would do just as well. – Marc B Aug 22 '14 at 21:50
  • 1
    Possible duplicate of [.htaccess 301 redirect of single page](http://stackoverflow.com/questions/1421068/htaccess-301-redirect-of-single-page) – jww Aug 23 '14 at 00:34
  • If I just use a simple redirect for the particular page only. Example: Redirect 301 /blog_rss.php http:// www.example.com/blog_rss.php It causes a redirect loop since I have a global redirect to https. – David Friedman Aug 25 '14 at 13:31

1 Answers1

2

You can replace your current code by this one in your htaccess

RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/blog_rss\.php$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,QSA]

RewriteCond %{HTTPS} on
RewriteRule ^(blog_rss\.php)$ http://%{HTTP_HOST}/$1 [R=301,L,QSA]

EDIT: looks like %{HTTPS} is not recognized on some servers, which is causing an infinite loop.

Try with %{SERVER_PORT} (if default http port is still 80 and ssl port is 443)

RewriteEngine On
RewriteBase /

RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/blog_rss\.php$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,QSA]

RewriteCond %{SERVER_PORT} 443
RewriteRule ^(blog_rss\.php)$ http://%{HTTP_HOST}/$1 [R=301,L,QSA]

You could also try with your initial syntax

RewriteEngine On
RewriteBase /

RewriteCond %{ENV:HTTPS} !on [NC]
RewriteCond %{REQUEST_URI} !^/blog_rss\.php$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,QSA]

RewriteCond %{ENV:HTTPS} on [NC]
RewriteRule ^(blog_rss\.php)$ http://%{HTTP_HOST}/$1 [R=301,L,QSA]
Justin Iurman
  • 18,954
  • 3
  • 35
  • 54
  • Hi Justin, thanks for your response but when I replace my current code with yours I receive an error. "The page isn't redirecting properly. Firefox has detected that the server is redirecting the request for this address in a way that will never complete." Do I replace {HTTP_HOST} with my domain name? – David Friedman Aug 25 '14 at 13:16
  • No you don't have to replace it, this code should work with a copy/paste. It seems you have other rules trying to redirect or maybe it's a cache problem (try with a new browser or clear your browser cache) – Justin Iurman Aug 25 '14 at 13:32
  • Thanks for your help. I removed all other redirects except for yours and tried it with a new browser/cleared cache but still same result. My goal is to setup a global redirect for all pages to be HTTPS except for blog_rss.php. I hope that was clear in my original posting. – David Friedman Aug 25 '14 at 13:36
  • That's what my code does (tested and working), your original post was clear enough. Is your htaccess in root level ? You must try only with my code (at least right now) – Justin Iurman Aug 25 '14 at 13:43
  • Yes my .htaccess is in the root. I literally deleted my entire .htaccess file, replaced it with your code, used a new browser, cleared my cache and the result is "This webpage has a redirect loop" The only URL I can access is example.com/blog_rss.php and it redirects to HTTPS. – David Friedman Aug 25 '14 at 13:51
  • So `http://example.com/blog_rss.php` redirects to `https://example.com/blog_rss.php` and `https://example.com/blog_rss.php` stays unchanged ? That's a good point. For the redirect loop, i don't understand since my code **can't** provide such a behaviour. For other than `blog_rss.php`, if it's `http` then it goes to `https` equivalent, that's all. Try to look at http headers to check where it wants to redirect in infinite loop (or give me url and i'll check myself) – Justin Iurman Aug 25 '14 at 14:04
  • I made a mistake, after I entered your code, I can access blog_rss.php through HTTP or HTTPS. No redirect is happening. Would you be willing to talk to me privately on Google+ or Skype and I can provide the URL? The reason being is that it's a client website and I don't want to leave the site broken for a long period of time. – David Friedman Aug 25 '14 at 14:40
  • Before everything, could you put my code again in your htaccess and give me the url ? This way i'll check http headers and search for errors. If problem persists then we'll have a private discussion – Justin Iurman Aug 25 '14 at 14:42
  • Sure...code was added to .htaccess. Website is helmerlegal.com. Thanks so much Justin! – David Friedman Aug 25 '14 at 14:50
  • Hi Justin. Did you have a chance to look? I'm just getting kind of worried because I can't have a client website offline for a long period of time. – David Friedman Aug 25 '14 at 15:29
  • Hi Justin. I really really appreciate your help but I can't keep the website offline for more than an hour. That's why I was hoping to chat with you privately when it's a good time for you to test the code and not have to leave the website offline for a long period of time when I don't know if you have had time to look at it or not. – David Friedman Aug 25 '14 at 15:51
  • Yep, i did test, thank you. There's an infinite loop but i can see only one reason (see my edited answer) – Justin Iurman Aug 25 '14 at 15:56
  • 1
    I used the second code that included the initial syntax and IT WORKED! You are a life safer! Thank you so much Justin! – David Friedman Aug 25 '14 at 16:08
  • I have used the code it's not working for me. I'm in same situation, I need to navigate http to https all pages except one particular url, ex if user https://www.example.com/index.php/C_booking/book this need to redirect http://www.example.com/index.php/C_booking/book. RewriteCond %{HTTPS} on [NC] RewriteRule ^book http://%{HTTP_HOST}/$1 [QSA,L] I have tried this code but not working – Vinoth Kumar Aug 02 '20 at 06:24