Redirecting a loop using CloudFlare and OpenShift and WordPress

I created a WordPress application on OpenShift and responded to the blog-porta8080.rhcloud.com URL.

I created 2 aliases on OpenShift

enter image description here

I bought my domain (porta8080.com.br) from a Brazilian registrar who does not allow me to add CNAME records without a subdomain such as www.

So, I created an account in CloudFlare, registered my domain and moved my domain to CloudFlare DNS servers.

enter image description here

Then I added 2 CNAME records to CloudFlare

enter image description here

I even installed the CloudFlare plugin, which they say will help me

https://wordpress.org/plugins/cloudflare/

But when I go to http://porta8080.com.br , it cannot load the page due to redirect loop error. I tested on chrome and on Firefox, and both of them give the same error. Chrome says “ERR_TOO_MANY_REDIRECTS” and checks the requests, it gives me some errors “301: moving forever”

enter image description here

The wp-admin page does not give me an error. The only thing I can think of is his own .htaccess file.

This is my .htaccess (the one in Openshift probably doesn't have blog/ parts, I just changed the permalink in both and that got the .htaccess on my machine)

 # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /blog/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /blog/index.php [L] </IfModule> # END WordPress 

Any ideas?

@Edit

There is a problem on my .htaccess. I commented on this and put the message in the index file, and it gets there both through www, and without it.

Could you guess why?

+5
source share
1 answer

This is an interesting issue when you use the CloudFlare Flexible SSL option next to WordPress. WordPress has an is_ssl function in is_ssl , which does not take into account reverse proxies. Therefore, when redirecting to SSL, you can get a redirect cycle when using flexible SSL .

The easiest way to fix this is to install Mod_cloudflare on Apache.

Instead, you can add an if statement to the wp-config.php file to solve this problem:

 if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { $_SERVER['HTTPS'] = 'on'; } 

If you use this method instead of setting Mod_cloudflare, make sure that instead of forwarding you use the "X-Forwarded-Proto" header instead of SSL.

+1
source

All Articles