Avatar of Luey
Luey
Flag for United States of America asked on

mod_rewrite to https or http

I have a rewrite rule in my htaccess file that sends all traffic to https.  I have a unique situation that requires one page in my site to not be redirected to https.  How can I accomplish this.

This is the rule I am using to send everything to https.
RewriteRule ^(.*)$ https://www.bumpum.com/$1 [R=301,L]

Open in new window


However, I need this rule to go to http instead.
RewriteRule ^/?fb/(.*)$ /social_redirects.php?sign_serial=$1  [QSA,NC,L]

Open in new window

Apache Web ServerPHP

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
Dan Craciun

Not tested, but you could negate the request URI before the https rule:
RewriteCond %{REQUEST_URI} !^/?fb/(.*)$
RewriteRule ^(.*)$ https://www.bumpum.com/$1 [R=301,L]

Open in new window

HTH,
Dan
Luey

ASKER
Dan I tested that and it still redirects to https any more ideas?
Dan Craciun

Weird. It should of worked.

Anyway, add the full path to the second rule.

RewriteRule ^/?fb/(.*)$ http://www.bumpum.com/social_redirects.php?sign_serial=$1  [QSA,NC,L]

Open in new window

Your help has saved me hundreds of hours of internet surfing.
fblack61
Luey

ASKER
If I put it like this it still does not work.  Still redirects all to https
RewriteRule ^(.*)$ https://www.bumpum.com/$1 [R=301,L] 
RewriteRule ^/?fb/(.*)$ http://www.bumpum.com/social_redirects.php?sign_serial=$1  [QSA,NC,L] 

Open in new window


If I put it like this it fails in the browser and says this webpage has a redirect loop.
RewriteRule ^/?fb/(.*)$ http://www.bumpum.com/social_redirects.php?sign_serial=$1  [QSA,NC,L] 
RewriteRule ^(.*)$ https://www.bumpum.com/$1 [R=301,L]

Open in new window

Dan Craciun

Both rules have an L at the end, meaning they are the last rules used, if true.

So yes, this:
RewriteRule ^(.*)$ https://www.bumpum.com/$1 [R=301,L] 
RewriteRule ^/?fb/(.*)$ http://www.bumpum.com/social_redirects.php?sign_serial=$1  [QSA,NC,L]

Open in new window

will always match rule number 1, and never even try rule number 2

But reversing the order should produce correct results: if the page is of the form http://www.bumpum.com/fb/something then the first rule is applied and the next is ignored, if not then the second rule is applied.

Can you please try another browser? Maybe it's a caching issue.
Luey

ASKER
I have now tried multiple browsers and multiple computers.  I always get the same results.  

If i put this first it comes back with a browser failure (redirect loop)  Its like the L is not working at all.
RewriteRule ^/?fb/(.*)$ http://www.bumpum.com/social_redirects.php?sign_serial=$1  [QSA,NC,L]

Open in new window


I also tried it like this and it does not work either.  I removed the L thinking it might move to the next rule but does not work.  I tried every combination I can think of.
RewriteRule ^(.*)$ https://www.bumpum.com/$1 [R=301] 
RewriteRule ^/?fb/(.*)$ http://www.bumpum.com/social_redirects.php?sign_serial=$1  [QSA,NC,L]

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Steve Bink

Same solution as Dan, but you also need to exempt /social_redirects.php from the https redirect.
Ray Paseur

In PHP you can detect HTTPS and use header("Location:...") to redirect the browser.  You would want to be mindful of the risk of complex interaction between .htaccess and the PHP redirect.
http://php.net/manual/en/reserved.variables.server.php
BigRat

I have a very similar problem to this one.

All traffic to a site must be https, so I rewrite all URLS to redirect to https.
BUT I have one URL which comes not from the browser but an embedded activeX control which must go directly to CGI. This does not work.

I'm still fiddling, so I'll keep you posted.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Luey

ASKER
@ray - the reason I cannot use that is I am using NFC technology in my application to redirect to a social media ap and if I send it to https first it opens up a browser window and sends them to the site in the browser which is not what I want to do.  If I use http: it sends them to my redirect page then the phone prompts the user to use their social ap to open and that is what I want to do.  So I only need the one page to go to http: and all others to go to https:  It will need to be done in the rewrite.

@Steve - I do not know how to implement what you are saying.  If you could give me an example it would be greatly appreciated.
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Luey

ASKER
That sounds like a great solution Ray.  I will implement that and see how well it works out.  Thanks
Ray Paseur

Good luck with it.  I'm pretty sure it's sound in theory, so if you have any issues implementing it in practice, please post back here and we will be glad to help!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.