0

Migrated the site from http to https.The homepage is working fine the but other page(archive,single,page) templates are resulting in 404.

Here are the steps while migrating.Could anyone please point out where I am going wrong?

  • Changed site name and site url to https scheme.

  • Then added the following htaccess rule.

       <IfModule mod_rewrite.c>
           RewriteEngine on
           RewriteCond %{HTTPS} !=on [NC]
           RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
       </IfModule> 
    
  • Flushed the rewrite rules with flush_rewrite_rules().

The home and admin pages are fine but the single or the archive pages.This seems like the rewrite rules are not working with https scheme.

Could anyone please point me in the right direction?

  • 1
    "something is not working" is unlikely to get productive answers without giving as much details as you can. We don't have access to your server and telling you how to debug things is frankly too boring. start with you url structure, full htacces and what happens when you switch off plugins and use default theme. – Mark Kaplun May 20 '16 at 8:00
  • stackoverflow.com/a/30318921/1031689 worked for me – JasonPlutext May 3 '17 at 3:59
0

You can use template_redirect to force all the http traffic going through WordPress to use https:

function force_secure_navigation() {

    if ( ! is_ssl() ) :

        $url = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

        wp_redirect( $url, 301 );

        exit();

    endif;

}

add_action( 'template_redirect', 'force_secure_navigation', 1 );

Remember that if you are working with https it's important to also serve your external resources, such as jQuery, Google Fonts or whatever is loading from a CDN, using https. You might want to check your wp_enqueue_style and wp_enqueue_script hooks to be sure there are no http calls left.

  • The template redirect does the same thing as a htaccess rule right?My redirection is working but its not picking up the right template. – Varun Hegde May 20 '16 at 8:37
  • With template_redirect you can access the queried object and use conditionals, such as is_user_logged_in(), is_admin(), etcetera. If you intend to redirect all the traffic to https then, yes, it's virtually the same but probably less performant. – Luis Sanz May 20 '16 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.