Post by omarzambri » Mon Aug 28, 2017 6:56 pm

(Note: our domain name is re-named to "mydomain" in the .htaccess contents as listed below).

The Problem:
Visitors suddenly got the following error when visiting our website:

This page isn’t working
www.mydomain.com redirected you too many times.
Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS

All browsers gave the same problem, so looks like a server-side problem, perhaps our .htaccess file has errors in logic. Suspicion is that there is "looping" in our .htaccess file but surprised that this problem never surfaced before. I am listing below the contents of my .htaccess file and hoping anyone can advise me, of where the problem is or what is causing the many "re-directs"? Appreciate it as my website is now down for many days and not accessible!

Content of .htaccess file is per below:

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.
# 2. In your opencart directory rename htaccess.txt to .htaccess.
# For any support issues please visit: http://www.opencart.com
# BEGIN WordPress HTTPS Force

RewriteEngine On
#we replace domain.com/$1 with %{SERVER_NAME}%{REQUEST_URI}.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*) http://www.%{SERVER_NAME}%{REQUEST_URI} [L,R=301]

#here we dont use www as non www was already redirected to www.
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
# END WordPress HTTPS Force


Options +FollowSymlinks

# Prevent Directoy listing
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini|log)">
Order deny,allow
Deny from all
</FilesMatch>

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

RewriteBase /
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R,L]


### Additional Settings that may need to be enabled for some servers
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

# 7. disable open_basedir limitations
# php_admin_value open_basedir none

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php54” package as the default “PHP” programming language.
<IfModule mime_module>
AddType application/x-httpd-ea-php54 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

Newbie

Posts

Joined
Mon Aug 28, 2017 5:52 pm

Post by victorj » Tue Aug 29, 2017 4:36 am

there are to many rewrites in your htaccess to try to force going to www and https.
Keep it simple.
Just remove everything in your htaccess and paste code below, replace mydomain.com with your domain name with or without www.

Cpanel will add all needed lines for your ssl certificate.

Code: Select all

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled. 

# 2. In your opencart directory rename htaccess.txt to .htaccess.

# For any support issues please visit: http://www.opencart.com

Options +FollowSymlinks

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://mydomain.com/$1 [R=301,L]

RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ https://mydomain.com/$1 [R=301,L]

# Prevent Directoy listing 
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
 Order deny,allow
 Deny from all
</FilesMatch>

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/ 

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

### Additional Settings that may need to be enabled for some servers 
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

# 7. disable open_basedir limitations
# php_admin_value open_basedir none

Koeltechnische deurrubbers eenvoudig online op maat bestellen.
Alle niet stekplichtige onderdelen zoals scharnieren, sloten, randverwarming en verlichting voor alle typen koelingen en vriezers.
https://koelcel-onderdelen.com

Koeltechnische deurrubbers eenvoudig online op maat bestellen.
Eigen productie en snelle levering.
https://123-deurrubbers.com


User avatar
Expert Member

Posts

Joined
Sat Jun 25, 2011 4:09 am
Location - Alkmaar Holland

Post by omarzambri » Tue Aug 29, 2017 6:04 pm

Thank you for the response.
We tested the new htaccess statements as proposed but we still got the "too many re-directs" error message and in more pages than before.
When our original htaccess file was activated, only visits to the main page https://www.mydomain.com resulted in the "too many re-directs" error message. Direct visits to other website pages, however, were still possible, eg: visit to the URL https://www.domain.com/training

When we changed the htaccess file to contain the statements as proposed in response from Victorj, the error message "too many re-directs" occurred when visiting all pages.

The above is the observation. Hoping to get feeback. Tq.

Newbie

Posts

Joined
Mon Aug 28, 2017 5:52 pm

Post by MrPhil » Wed Aug 30, 2017 5:14 am

In your first post, I see you have the rewrite flags reversed from normal practice. Make sure they are like [R=301,L]. At least some servers may not handle it correctly if you tell it to "Leave" first, and then give the 301 rewrite code.

You also have multiple instances of rewriting non-www to www and http to https, including redirecting to http (with www) and then redirecting to https (without www) -- that alone may be looping problem. Don't use SERVER_NAME: use your hard coded domain name.

Try this, it will work on almost all servers:

Code: Select all

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.
# 2. In your opencart directory rename htaccess.txt to .htaccess.
# For any support issues please visit: http://www.opencart.com

RewriteEngine On
# 30x redirects (visible to user and search engines) always do first
# non-www domain, change to www form. http, change to https
RewriteCond %{HTTPS}  !on  [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]

# some hosts don't allow Options commands
Options +FollowSymlinks

# Prevent Directory listing
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini|log)">
Order deny,allow
Deny from all
</FilesMatch>

# SEO URL Settings
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

RewriteBase /
# 3 special cases
RewriteRule ^sitemap\.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase\.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
# general SEO, for paths/files that don't really exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

### Additional Settings that may need to be enabled for some servers
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.
# Note that most servers do not permit php_value and php_flag -- these settings have to go in php.ini

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

# 7. disable open_basedir limitations
# php_admin_value open_basedir none

# php -- BEGIN cPanel-generated handler, do not edit
# POSSIBLY odd quotation marks in following line, and edited in UTF-8
# By the way, PHP 5.4 is very obsolete. you should be at 5.6 at a minimum (7.1 is current)
# Set the “ea-php54” package as the default “PHP” programming language.
<IfModule mime_module>
AddType application/x-httpd-ea-php54 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
Last edited by MrPhil on Wed Aug 30, 2017 5:31 am, edited 1 time in total.

Active Member

Posts

Joined
Wed May 10, 2017 11:52 pm

Post by victorj » Wed Aug 30, 2017 5:19 am

replace

Code: Select all

RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ https://mydomain.com/$1 [R=301,L]
with

Code: Select all

#RewriteCond %{SERVER_PORT} 443
#RewriteRule ^(.*)$ https://mydomain.com/$1 [R=301,L]
try again and it should work

Koeltechnische deurrubbers eenvoudig online op maat bestellen.
Alle niet stekplichtige onderdelen zoals scharnieren, sloten, randverwarming en verlichting voor alle typen koelingen en vriezers.
https://koelcel-onderdelen.com

Koeltechnische deurrubbers eenvoudig online op maat bestellen.
Eigen productie en snelle levering.
https://123-deurrubbers.com


User avatar
Expert Member

Posts

Joined
Sat Jun 25, 2011 4:09 am
Location - Alkmaar Holland

Post by omarzambri » Thu Aug 31, 2017 6:08 pm

victorJ and MrPhil,
Thank you very much for the responses. For completeness, I did test both of the suggestions and here are the results:

victorj proposal:

Eureka. After making corrections as suggested by adding the "#" in the beginning of two (2) of the statements, the "too many re-directs" was resolved. I can now visit the main page of my website www.mydomain.com and so are the other pages. I am still in the midst of testing other pages in detail.

The only side-effect, is that I noticed, the server settings if set to "Maintenance Mode" to "ON" does not work anymore.
Despite the setting for Maintenance Mode is set to "On", the visitor still be able to visit the main page and the other pages. Visitor will not see the "The website is on Maintenance. Be back again soon" message anymore and can proceed to perform transactions. I am not sure if actually this is because of the changed .htaccess file as proposed by victorJ. Nevertheless, I am grateful that the "too many re-direct" problem has gone.

MrPhil proposal:
Unfortunately, after the change made to the .htaccess file as proposed, all pages were not able to be visited, resulting in the message "too many re-directs". So, the proposal did not work.

I would like to thank victorj and MrPhil for being so helpful.

To MrPhil, I am willing to test your proposal again if you wish to see the result of any other change to your 1st proposal.

Newbie

Posts

Joined
Mon Aug 28, 2017 5:52 pm

Post by victorj » Thu Aug 31, 2017 6:12 pm

Remember as long as you are still logger in into admin, you Will be able to see entire website even in maintenance mode.
So make sure youre liggend out from admin and test maintenance mode.
If breder refreshes your browser by hitting shift F5 followed by cntr F5 to clear browser cache.

Koeltechnische deurrubbers eenvoudig online op maat bestellen.
Alle niet stekplichtige onderdelen zoals scharnieren, sloten, randverwarming en verlichting voor alle typen koelingen en vriezers.
https://koelcel-onderdelen.com

Koeltechnische deurrubbers eenvoudig online op maat bestellen.
Eigen productie en snelle levering.
https://123-deurrubbers.com


User avatar
Expert Member

Posts

Joined
Sat Jun 25, 2011 4:09 am
Location - Alkmaar Holland

Post by MrPhil » Thu Aug 31, 2017 9:25 pm

omarzambri wrote:
Thu Aug 31, 2017 6:08 pm
Unfortunately, after the change made to the .htaccess file as proposed, all pages were not able to be visited, resulting in the message "too many re-directs". So, the proposal did not work.
That's very odd. You must either have some strange configuration on your server, or made some change when implementing my suggested .htaccess. Anyway, it sounds like you're working now, so I won't bother with any additional proposals.

Active Member

Posts

Joined
Wed May 10, 2017 11:52 pm

Post by omarzambri » Thu Aug 31, 2017 10:54 pm

Hi victorj,
Thanks for the reminder that one need to be logged out as Opencart administrator for the Maintenance message to be displayed when Maintenance Mode is set to "On".
So, I was wrong. There was NO "side-effect" from the proposed .htaccess statements to resolve the "too many redirects" problem.

Thank you Victorj for the short, simple, elegant statements, to force www and https for a website and at same time resolve this problem. The solution will definitely be helpful to many. out there.

To MrPhil, thank you very much for spending the time and the contribution. It will be picked up by another and will be useful, I am certain.

Newbie

Posts

Joined
Mon Aug 28, 2017 5:52 pm
Who is online

Users browsing this forum: No registered users and 13 guests