• Just putting this out there for anyone that encounters the same issue once upgraded to WP 4.0

    Up to 3.9.2, the canonical redirect function did not seem to check the protocol when redirecting to the siteurl config, at least as far as I can tell.

    That means the HTTPS auto-redirect was done in the htaccess file based on the X-FORWARDED-PROTO header present in the request from the load balancer.

    WP 4.0 seems to now check the protocol if the siteurl is set to https://*, which results in a redirect loop since Beanstalk applications use standard HTTP requests behind the load balancer.

    If you are caught unable to access your site which auto-redirects to HTTPS, you can fix it with the following steps:

    1. Change the ‘siteurl’ and ‘home’ options in the wp_options database table to be http only.

    2. Temporarily disable any HTTPS redirects in the htaccess file, this should get you access to the admin panel at least.

    3. Install the canonical redirect disabler from here into the /plugins directory

    4. Activate the redirect disabler plugin

    5. Set the site URL and home address in Settings -> General back to HTTPS

    6. Re-instate the HTTPS redirect in the htaccess file based on the X-FORWARDED-PROTO header

    You should now have auto-redirect to SSL functioning correctly again. Hope this helps anyone that faces the same issue.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thank you, thank you, thank you! We weren’t having the exact problem you described, but have spent hours investigating a weird redirect loop error on one of our SSL pages.

    I can’t believe a single line of code was all we needed:
    remove_filter(‘template_redirect’, ‘redirect_canonical’);

    Thanks for taking the time to write this up!

    Thank you!!!!! This just took me about 2 hours to fix and this solution worked!

    For anybody else who comes across this, the HTTPS redirect you need in .htaccess is:
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
    </IfModule>

    I put this above the # BEGIN WordPress entries and it worked perfectly 🙂

    WOW! Turns out this isn’t just as simple as adding the above.

    The above seemed to work but then Elastic Beanstalk health checks actually end up failing.

    I tried adding a dedicated file to the health check but this still failed, it turns out you need to exclude the dedicated health check file and the health checker path for this to work.

    Here’s my full .htaccess

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteCond %{REQUEST_URI} !^/status\.html$
    RewriteCond %{REQUEST_URI} !^/_hostmanager/
    RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
    </IfModule>
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    Remember to change status.html to whatever your health check path is

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘WordPress SSL & AWS Elastic Beanstalk Redirect Loop’ is closed to new replies.