amann
amann

Reputation: 5912

OpenShift Redirect Loop between www and non-www

I'm experiencing an infinite redirect loop when I try to access my site. The redirect loop seems to be between the non-www version and the www version.

My DNS has a URL Redirect set for http://domain.tld to www.domain.tld. Then www.domain.tld has a CNAME record for app-namespace.rhcloud.com.

For the app I added the alias www.domain.tld

I've also tried to add an alias for domain.tld, but that doesn't help.

Is there something I'm missing? Thank you very much for your help!

Upvotes: 1

Views: 843

Answers (2)

Tarek Adam
Tarek Adam

Reputation: 3535

I'm hosting a laravel 5 project on openshift. www and non-www are tricky but I finally got it working with a simple 2 part solution...

  1. since you can't use non-www for a cname, make it an A-record to 174.129.25.170 and they will add the www. That's all they seem to do. Weird, I know.

  2. Use this in your .htaccess It seems to work better in cloud situations.

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

Upvotes: 2

amann
amann

Reputation: 5912

I found the issue. It was due to a redirect from www.domain.tld to domain.tld that was caused by a rewrite rule in the .htaccess file:

<IfModule mod_rewrite.c> #RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L] </IfModule>

Removing this resolved the issue.

Upvotes: 1

Related Questions