mjurmann Posted November 12, 2008 Share Posted November 12, 2008 Hello. I need to redirect all https requests to http, however, I need to make one exception for a single page on the site. All of the pages redirect from https to http correctly, however, when the exception page is loaded, there is a "Redirect Loop" error displayed. Can someone please tell me where I'm going wrong? Thanks. # Ensure Correct Host RewriteCond %{HTTP_HOST} ^domain\.com$ RewriteRule (.*) http://www.domain.com/$1 [R=301] # SSL Exception Here RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^pay-invoice https://%{HTTP_HOST}/pay-invoice [R,L] # Not Anywhere Else RewriteCond %{SERVER_PORT} !^80$ RewriteCond %{REQUEST_URI} !^pay-invoice RewriteRule .? http://www.domain.com%{REQUEST_URI} [R,L] Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/ Share on other sites More sharing options...
mjurmann Posted November 12, 2008 Author Share Posted November 12, 2008 Does anyone have any ideas here? This infinite loop is a real pain. Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-688198 Share on other sites More sharing options...
corbin Posted November 12, 2008 Share Posted November 12, 2008 # SSL Exception Here RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^pay-invoice https://%{HTTP_HOST}/pay-invoice [R,L] Of course it's looping. You're saying: "If it's port 443 and the page starts with pay-invoice, redirect it to pay-invoice." Wouldn't pay-invoice start with pay-invoice and be on port 433? Try removing the #SSL exception block and it should work, since the Not Anywhere Else blcok should catch it. Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-688211 Share on other sites More sharing options...
foxtrotwhiskey Posted November 12, 2008 Share Posted November 12, 2008 I set my server up to test this code and I finally figured out what is wrong. The %{REQUEST_URI} var includes the slash at the beginning, and your RewriteCond does not include that slash so it is not preventing the third RewriteRule from executing, thus causing the loop. Try this code: # Ensure Correct Host RewriteCond %{HTTP_HOST} ^domain\.com$ RewriteRule (.*) http://www.domain.com/$1 [R=301] # SSL Exception Here RewriteCond %{SERVER_PORT} !^443$ RewriteCond %{REQUEST_URI} ^/pay-invoice RewriteRule (.*) https://%{HTTP_HOST}/$1 [R,L] # Not Anywhere Else RewriteCond %{SERVER_PORT} !^80$ RewriteCond %{REQUEST_URI} !^/pay-invoice RewriteRule (.*) http://www.domain.com/$1 [R,L] Let me know if it works for you! Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-688219 Share on other sites More sharing options...
mjurmann Posted November 12, 2008 Author Share Posted November 12, 2008 # SSL Exception Here RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^pay-invoice https://%{HTTP_HOST}/pay-invoice [R,L] Of course it's looping. You're saying: "If it's port 443 and the page starts with pay-invoice, redirect it to pay-invoice." Wouldn't pay-invoice start with pay-invoice and be on port 433? Try removing the #SSL exception block and it should work, since the Not Anywhere Else blcok should catch it. Thanks for your help, however, when I remove that block, mod_rewrite no longer knows to forward the http to the https version of the pay-invoice page. Foxtrot - thanks for your help, but that didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-688796 Share on other sites More sharing options...
corbin Posted November 12, 2008 Share Posted November 12, 2008 Oh ignore what I said earlier. I chose not to read the !. lol.... What I said was entirely wrong. Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-688929 Share on other sites More sharing options...
mjurmann Posted November 12, 2008 Author Share Posted November 12, 2008 Oh ignore what I said earlier. I chose not to read the !. lol.... What I said was entirely wrong. No problem. Is this even possible? Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-688948 Share on other sites More sharing options...
corbin Posted November 12, 2008 Share Posted November 12, 2008 Yeah it's possible. Hrmmm... That's really weird.... RewriteEngine On # SSL Exception Here RewriteCond %{SERVER_PORT} !^443$ RewriteCond %{REQUEST_URI} ^/pay-invoice RewriteRule (.*) https://%{HTTP_HOST}/$1 [R,L] # Not Anywhere Else RewriteCond %{SERVER_PORT} !^80$ RewriteCond %{REQUEST_URI} !^/pay-invoice RewriteRule (.*) http://<myhost>/$1 [R,L] Just worked fine for me x.x. Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-688954 Share on other sites More sharing options...
mjurmann Posted November 12, 2008 Author Share Posted November 12, 2008 Yeah it's possible. Hrmmm... That's really weird.... RewriteEngine On # SSL Exception Here RewriteCond %{SERVER_PORT} !^443$ RewriteCond %{REQUEST_URI} ^/pay-invoice RewriteRule (.*) https://%{HTTP_HOST}/$1 [R,L] # Not Anywhere Else RewriteCond %{SERVER_PORT} !^80$ RewriteCond %{REQUEST_URI} !^/pay-invoice RewriteRule (.*) http://<myhost>/$1 [R,L] Just worked fine for me x.x. I copied and pasted that exact code and substituted the domain, however, there is still an infinite loop. Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-688959 Share on other sites More sharing options...
corbin Posted November 12, 2008 Share Posted November 12, 2008 Is # Ensure Correct Host RewriteCond %{HTTP_HOST} ^domain\.com$ RewriteRule (.*) http://www.domain.com/$1 [R=301] # SSL Exception Here RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^pay-invoice https://%{HTTP_HOST}/pay-invoice [R,L] # Not Anywhere Else RewriteCond %{SERVER_PORT} !^80$ RewriteCond %{REQUEST_URI} !^pay-invoice RewriteRule .? http://www.domain.com%{REQUEST_URI} [R,L] Your entire file? Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-688960 Share on other sites More sharing options...
mjurmann Posted November 13, 2008 Author Share Posted November 13, 2008 Here is what I currently have: # Ensure Correct Host RewriteCond %{HTTP_HOST} ^domain\.com$ RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] # SSL Exception Here RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^pay-invoice https://%{HTTP_HOST}/pay-invoice [R,L] # Not Anywhere Else RewriteCond %{SERVER_PORT} !^80$ RewriteCond %{REQUEST_URI} !^pay-invoice$ RewriteRule .? http://www.domain.com%{REQUEST_URI} [L,R=301] Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-688974 Share on other sites More sharing options...
corbin Posted November 13, 2008 Share Posted November 13, 2008 RewriteCond %{REQUEST_URI} !^pay-invoice$ Change that to RewriteCond %{REQUEST_URI} !^pay-invoice The $ means the end. So, that means if the request URI is not exactly equal to "pay-invoice". I'm assuming you want if the request URI does not start with pay-invoice. Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-688982 Share on other sites More sharing options...
mjurmann Posted November 13, 2008 Author Share Posted November 13, 2008 Unfortunately, this is still giving us an infinite loop on the pay-invoice page only. # Ensure Correct Host RewriteCond %{HTTP_HOST} ^domain\.com$ RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] # SSL Exception Here RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^pay-invoice https://%{HTTP_HOST}/pay-invoice [R,L] # Not Anywhere Else RewriteCond %{SERVER_PORT} !^80$ RewriteCond %{REQUEST_URI} !^pay-invoice RewriteRule .? http://www.domain.com%{REQUEST_URI} [L,R=301] Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-688991 Share on other sites More sharing options...
corbin Posted November 13, 2008 Share Posted November 13, 2008 Hrmmm, it would seem that SERVER_PORT is never 443.... Try changing # SSL Exception Here RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^pay-invoice https://%{HTTP_HOST}/pay-invoice [R,L] to # SSL Exception Here RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^pay-invoice https://%{HTTP_HOST}/pay-invoice/%{SERVER_PORT} [R,L] Temporarily so we can see what SERVER_PORT Is. Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-688999 Share on other sites More sharing options...
mjurmann Posted November 13, 2008 Author Share Posted November 13, 2008 Hrmmm, it would seem that SERVER_PORT is never 443.... Try changing # SSL Exception Here RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^pay-invoice https://%{HTTP_HOST}/pay-invoice [R,L] to # SSL Exception Here RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^pay-invoice https://%{HTTP_HOST}/pay-invoice/%{SERVER_PORT} [R,L] Temporarily so we can see what SERVER_PORT Is. https://www.domain.com/pay-invoice/80 Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-689003 Share on other sites More sharing options...
mjurmann Posted November 13, 2008 Author Share Posted November 13, 2008 Hrmmm, it would seem that SERVER_PORT is never 443.... Try changing # SSL Exception Here RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^pay-invoice https://%{HTTP_HOST}/pay-invoice [R,L] to # SSL Exception Here RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^pay-invoice https://%{HTTP_HOST}/pay-invoice/%{SERVER_PORT} [R,L] Temporarily so we can see what SERVER_PORT Is. https://www.domain.com/pay-invoice/80 However, when I changed: # Not Anywhere Else RewriteCond %{SERVER_PORT} !^80$ RewriteRule .? http://www.domain.com%{REQUEST_URI}/%{SERVER_PORT} [L,R=301] and refreshed the https://www.domain.com/pay-invoice page, it returned, http://www.domain.com/pay-invoice/443 Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-689005 Share on other sites More sharing options...
foxtrotwhiskey Posted November 13, 2008 Share Posted November 13, 2008 Your: RewriteCond %{REQUEST_URI} ^pay-invoice$ and RewriteCond %{REQUEST_URI} !^pay-invoice$ Should be: RewriteCond %{REQUEST_URI} ^/pay-invoice$ and RewriteCond %{REQUEST_URI} !^/pay-invoice$ respectively. Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-689058 Share on other sites More sharing options...
mjurmann Posted November 13, 2008 Author Share Posted November 13, 2008 Your: RewriteCond %{REQUEST_URI} ^pay-invoice$ and RewriteCond %{REQUEST_URI} !^pay-invoice$ Should be: RewriteCond %{REQUEST_URI} ^/pay-invoice$ and RewriteCond %{REQUEST_URI} !^/pay-invoice$ respectively. We're using the Drupal CMS, so unfortunately, that change does not work either. Quote Link to comment https://forums.phpfreaks.com/topic/132360-htaccess-issue/#findComment-689059 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.