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!

5
  • RewriteRule ^blog_rss.php etc...?
    – Marc B
    Aug 22, 2014 at 21:47
  • Can you please clarify? Aug 22, 2014 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, 2014 at 21:50
  • 1
    Possible duplicate of .htaccess 301 redirect of single page
    – jww
    Aug 23, 2014 at 0: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. Aug 25, 2014 at 13:31

1 Answer 1

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]
14
  • 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? Aug 25, 2014 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) Aug 25, 2014 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. Aug 25, 2014 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) Aug 25, 2014 at 13:43
  • 1
    I used the second code that included the initial syntax and IT WORKED! You are a life safer! Thank you so much Justin! Aug 25, 2014 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.