1. This website uses cookies to improve service and provide a tailored user experience. By using this site, you agree to this use. See our Cookie Policy.
    Dismiss Notice

Rewrite 302 redirect to 301 redirect after switching to https

Discussion in 'White Hat SEO' started by Celestial711, Oct 4, 2017.

  1. Celestial711

    Celestial711 Newbie

    Joined:
    Jun 9, 2015
    Messages:
    30
    Likes Received:
    1
    I recently moved a site from http to https and then re-directed all my links with https://pastebin.com/rQCnRuBu. It worked and all my links are now redirected to https. I ran an audit with Website Auditor by Link Assistant and it says the site has issues with duplicate http and https and www and non www versions of the site. It appears that my homepage is a 302 re-direct and should be a permanent 301 redirect. Any thoughts on solving matter ?
     
  2. SpoonFeeder

    SpoonFeeder Jr. VIP Jr. VIP

    Joined:
    Mar 19, 2017
    Messages:
    1,606
    Likes Received:
    1,978
    Gender:
    Male
    Occupation:
    SpoonFeeding & Babysitting the Noobs.
    Location:
    Click the link below if you're new to BHW!
    Home Page:
    Enter the following code in your .htaccess

    Code:
    RewriteEngine On
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]
    It'll 301 redirect non-www to www version as well as http requests to https.
     
    • Thanks Thanks x 1
  3. Celestial711

    Celestial711 Newbie

    Joined:
    Jun 9, 2015
    Messages:
    30
    Likes Received:
    1
    My website is set to non www not www - is the code still valid?
     
  4. SpoonFeeder

    SpoonFeeder Jr. VIP Jr. VIP

    Joined:
    Mar 19, 2017
    Messages:
    1,606
    Likes Received:
    1,978
    Gender:
    Male
    Occupation:
    SpoonFeeding & Babysitting the Noobs.
    Location:
    Click the link below if you're new to BHW!
    Home Page:

    The previous code will redirect non www to www. If you want to redirect www.example.com to example.com, use this code instead. Your site will then load at https://example.com

    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www.example.com [NC]
    RewriteRule ^(.*)$ https://example.com/$1 [L,R=301,NC]
    You can PM me the url if you want me to test if it's working as it should.
     
    • Thanks Thanks x 1
  5. persysweb

    persysweb Regular Member

    Joined:
    Aug 1, 2017
    Messages:
    330
    Likes Received:
    49
    Occupation:
    Web designing and hosting
    Location:
    India
    If you've working SSL certificate on your website and you'd like force your website to load using 'https' in web-browser then feel free to add the below code in '.htaccess' file under root directory-

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
     
    • Thanks Thanks x 1