skip to Main Content

I have web page created in WordPress v5.4, Theme Twenty Twelve and just installed SSL certificate.

I want to have such redirection structure (redirection codes in rectangles), to optimize for SEO:

enter image description here

but according to Google Chrome Site Inspector I have the follwing one:

enter image description here

So the schema is not fully optimized as for two cases there are dwo cascade redirections whereas should be one.

What is weird, current schema doesn’t reflect .htaccess file. My .htaccess file looks as follows:

# 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

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

So, my understanding of the code is that if url is typed in without https://, script rewrites it into version with https:// an nothing else, so there must be another place where other redirections (e.g. with www -> without www) are being made.

I have checked index.php – no redirections.

I also checked additional lines in .htaccess file don’t overwrite those “hidden” ones, so if I simply add them I got multiple redirections error in web browser.

Could you please advise me what else should I do to get desired structure of redirections?

2

Answers


  1. I’m guessing the redirect from www to non-www is due to the address you’ve set in your settings (WordPress dashboard → Settings → General).

    For the redirect you want to achieve, you have to add rewrite conditions for the www. in your .htaccess

    RewriteEngine On
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www. [NC]
    RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
    
    Login or Signup to reply.
  2. First rule redirect all www to https://domainname.com/, second all http to https://domainname.com/, one hop

    <IfModule mod_rewrite.c>
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^www. [NC]
    RewriteRule (.*) https://domainname.com/$1 [R=301,L]
    
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://domainname.com/$1 [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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search