"Too Many Redirects" SSL

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
brentnl
Power Poster
Power Poster
Posts: 493
Joined: Mon May 11, 2009 4:35 pm

"Too Many Redirects" SSL

Post by brentnl »

Hi,

I have a problem which I've never had before; normally I always use a known hostingcompany and never had any issue's with SSL (they implement it for free at every domain you set-up).

But now I'm dealing with another host for some reason and apparently they have another approach of dealing with SSL. When I don't use the HTTPS option for a page in CMSMS everything works fine; you could access the page at both the HTTP or HTTPS version. But when I'm using the HTTPS-checkbox I'll get a 'Too Many Redirects' error from Google Chrome. It somehow got caught in a loop.

And another issue; normally I use this .htaccess to force everyone towards the HTTPS version;

Code: Select all

#Options +FollowSymLinks
  RewriteEngine on
  RewriteBase /

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Link to http://website.com then redirect to http://www.website.com
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] 

  # 301 Redirect all requests that don't contain a dot or trailing slash to
  # include a trailing slash
  # except for form POSTS
  RewriteCond %{REQUEST_URI} !/$
  RewriteCond %{REQUEST_URI} !\.
  RewriteCond %{REQUEST_METHOD} !POST$
  RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
 
  # Rewrites urls in the form of /parent/child/
  # but only rewrites if the requested URL is not a file or directory
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.+)$ index.php?page=$1 [QSA] 

But that doesn't work either, no matter Use HTTPS is checked or not.

I use mod_rewrite in my config.php for Pretty URL's.
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1629
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: "Too Many Redirects" SSL

Post by DIGI3 »

I would unset all of the 'use https for this page' options, that was a holdover from when you might only want one or two pages to be https. You can use the bulk feature of Content Manager to do this.

Once you've done that, revisit your htaccess and follow the logic. For example, you have:

Code: Select all

RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] 
The "L" in that rule means ignore all following rules, so it's not going to get the https rule added. You could replace all of it with these rules:

Code: Select all

# Force www: from http://stackoverflow.com/a/4958847/1078583
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Force SSL: From http://stackoverflow.com/q/24322035/
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
Or, if you want NO www added, you can use:

Code: Select all

#force non-www and https
RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]
There's lots of other ways to write it, but the order matters, and the placement of parameters such as 'L' is important.
Not getting the answer you need? CMSMS support options
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: "Too Many Redirects" SSL

Post by Rolf »

- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
brentnl
Power Poster
Power Poster
Posts: 493
Joined: Mon May 11, 2009 4:35 pm

Re: "Too Many Redirects" SSL

Post by brentnl »

I've unchecked every 'use https' box and I've tried both htaccess versions, of both Rolf and DIGI3, both non of them seem to work. 'Too Many Redirects' is the error I keep getting..

I've submitted a ticket at the hosting company, Argeweb, so they will have a look at it as well.
brentnl
Power Poster
Power Poster
Posts: 493
Joined: Mon May 11, 2009 4:35 pm

Re: "Too Many Redirects" SSL

Post by brentnl »

Nobody?

If I visit the website while adding 'https' the homepage works normally but as soon as I navigate to another menu-item it serves me the HTTP version instead..

The hosting company couldn't help me as well.
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1629
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: "Too Many Redirects" SSL

Post by DIGI3 »

Do you have any urls entered into your config.php?
Not getting the answer you need? CMSMS support options
brentnl
Power Poster
Power Poster
Posts: 493
Joined: Mon May 11, 2009 4:35 pm

Re: "Too Many Redirects" SSL

Post by brentnl »

DIGI3 wrote:Do you have any urls entered into your config.php?

Code: Select all

$config['dbms'] = 'mysqli';
$config['db_hostname'] = '---';
$config['db_username'] = '---';
$config['db_password'] = '---';
$config['db_name'] = '---';
$config['db_prefix'] = 'cmssite_';
$config['timezone'] = 'Europe/Amsterdam';
$config['admin_dir'] = 'inloggen';
$config['query_var'] = 'pagina';
$config['url_rewriting'] = 'mod_rewrite';
$config['permissive_smarty'] = 1;
$config['root_url'] = 'https://www.domain.nl';
$config['admin_url'] = 'https://www.domain.nl/inloggen';
This is my config file..
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1629
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: "Too Many Redirects" SSL

Post by DIGI3 »

Nothing obvious there. Are you able to share the url to the site?
Not getting the answer you need? CMSMS support options
brentnl
Power Poster
Power Poster
Posts: 493
Joined: Mon May 11, 2009 4:35 pm

Re: "Too Many Redirects" SSL

Post by brentnl »

DIGI3 wrote:Nothing obvious there. Are you able to share the url to the site?
www.partycrew.nl
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1629
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: "Too Many Redirects" SSL

Post by DIGI3 »

Looks like an htaccess issue to me. When you hover over the links they are https, but when clicked they redirect to http. You should be able to test that by temporarily replacing htaccess with the htaccess.txt sample from the docs directory.

Make sure to check higher level directories for .htcaccess files as well, they're recursive.
Not getting the answer you need? CMSMS support options
brentnl
Power Poster
Power Poster
Posts: 493
Joined: Mon May 11, 2009 4:35 pm

Re: "Too Many Redirects" SSL

Post by brentnl »

DIGI3 wrote:Looks like an htaccess issue to me. When you hover over the links they are https, but when clicked they redirect to http. You should be able to test that by temporarily replacing htaccess with the htaccess.txt sample from the docs directory.

Make sure to check higher level directories for .htcaccess files as well, they're recursive.
There are no top-level .htaccess-files present and I've tried the htaccess.txt from /doc and it works fine, so the problem must have something to do with the htaccess combined with the server-settings?

The only thing remaining is forcing non-https request to the https-url. Any suggestions?
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1629
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: "Too Many Redirects" SSL

Post by DIGI3 »

If it works fine with the stock htaccess, then you just need to troubleshoot what is wrong with yours. Typically it's an order of operations thing, it needs to be quite specific. Some trial and error and/or googling may be in order.
Not getting the answer you need? CMSMS support options
Post Reply

Return to “CMSMS Core”