Mobile app version of vmapp.org
Login or Join
Ann8826881

: Redirect subdomain http:// to https:// - too many redirects I'm trying to redirect http://sub.domain.com to https://sub.domain.com. I have turned the web upside down trying every .htaccess and PHP

@Ann8826881

Posted in: #Cloudflare #Htaccess #Http #Https #Redirects

I'm trying to redirect sub.domain.com to sub.domain.com.
I have turned the web upside down trying every .htaccess and PHP script out there, and all of them give me the "Too Many Redirects" error.

I'm not so much looking for a solution, as I have pretty much given up on that.

What I'm wondering why I get the error? What does the error actually mean? As far as I can tell, all the scripts I've tried only ever redirect once.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Ann8826881

2 Comments

Sorted by latest first Latest Oldest Best

 

@Sherry384

See the following from CloudFlare: How do I fix the infinite redirect loop error after enabling Flexible SSL with WordPress?



Some users may experience redirect loops after activating CloudFlare’s free Universal Flexible SSL option. In order to fix this issue and/or get things set please follow the steps outlined below:
**

WordPress Site

**
1. Install either CloudFlare Flexible SSL WordPress plugin or WordPress HTTPS plugin. Many WordPress users are using these plugins to resolve redirect loop issues in WordPress and to make the transition to easier.


Note: These plugins were not created by CloudFlare.com



Install the CloudFlare WordPress plugin to make sure that the original visitor IP is being passed back at the WordPress level. Since it is likely that some of your other plugins rely on original visitor IP, installing the CloudFlare WordPress plugin will restore visitor IPs back to the WordPress level and not show CloudFlare’s IPs.




Other sites

1.Go to your website over to see if your website loads. Given that you didn’t have the domain set to use SSL prior to activating Universal SSL, it is likely that you will have a mixed content error warning when you look in the corner of your browser window. In order to make this error go away, you will need to go through your site and make sure assets are being loaded over HTTPS and not HTTP. Solutions can be found at:

Mozilla’s tutorial on fixing mixed content errors

WordPress Plugin: SSL Insecure Content Fixer


Create a page rule with the Always Use HTTPS action for the pattern **http://*example.com/***, replacing example.com with your domain to redirect all HTTP requests to HTTPS at our edge.
If you are still seeing the error, check to make sure there are not any redirects created at your origin server. With WordPress, these will generally be created in the ".htaccess" file. If you are using the Page Rule above, remove any redirect code here to prevent any infinite loops. Otherwise, if you'd prefer to use the redirect implemented on your server rather than the Page Rule, the redirect code may need to use the "X-Forwarded-Proto" header which checks the protocol sent from the visitor. The code itself would look like this:

RewriteCond %{HTTP:X-Forwarded-Proto} =http RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


This will have the redirect only trigger on HTTP connections, preventing the loop from occurring.

10% popularity Vote Up Vote Down


 

@LarsenBagley505

the "Too many redirects" issue comes from the fact that redirects are tied together. For example, example.com redirects to example.com and example.com redirects back to example.com.

This process can repeat itself over and over again until the redirect count established by the server is reached, then when that is exceeded, the server then stops trying to process redirects.

In apache, this can be discovered by seeing the "this page can be found here" message on the screen (which is an actual redirect page) instead of the behind-the-scenes automatic redirect that the browser processes.

What I would suggest you do when testing your scripts is to make them non-cacheable to get current results every time. You should also check to ensure the user requests the HTTPS version of the site, and only perform the redirect if the request isn't HTTPS. One way to check is to validate the server port number the user connects to and if the port number is 80 then make the redirect happen for the user since port 80 is HTTP.

Another thing helpful is to turn off automatic redirects in your browser while testing your pages.

If that is not possible, use redbot.org and put your URL that is causing problems in it then you'll see what the new URL is under "Location:" in the HTTP headers. Keep following the URL until you no longer see the "Location:" value. If you can't then you have an endless redirect.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme