1

I updated from http to https today. So far, so good. Everything is working, but the redirect command. When I click on external social media or websites that link to my blog still using the old version http, it's not being redirected.

This is how part of my file looks:

# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName zoomingjapan.com
AuthUserFile /home/zoomingj/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/zoomingj/public_html/_vti_pvt/service.grp
# 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]
RewriteCond %{HTTP_HOST} ^zoomingjapan.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.zoomingjapan.com [NC]
RewriteRule ^(.*)$ https://zoomingjapan.com/$1 [L,R=301,NC]
</IfModule>

# END WordPress

I also tried this instead, no positive result:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_USER_AGENT} !FeedBurner    [NC]
RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

This is an http link. You can test and see for yourself that it's not being redirected.

Could a caching plugin be interfering? I'm using LiteSpeed Cache.

3

You've put the redirect code in the wrong place. It needs to go before the # BEGIN WordPress section. By placing the redirect code after the WordPress front-controller it will never be processed unless the request is for a physical file.

However, your first attempt is not correct (it's missing the check for HTTPS), so would result in a redirect loop (if it was executed).

A standard HTTP to HTTPS would take the following form:

RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.example.com/$1 [R=301,L]

However, ideally you should also combine this with a canonical www/non-www redirect as well, to avoid duplicate content or multiple redirects. For example, if the preference is for www (and you have no other subdomains), then something like the following:

# Redirect bare domain to www and HTTPS
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.example.com/$1 [R=301,L]

# Redirect HTTP to HTTPS
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]

UPDATE: If your preference is for the non-www version, then you can change the first rule to read something like:

# Redirect www to non-www (and HTTPS)
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule (.*) https://example.com/$1 [R=301,L]

(Assuming you've also changed the necessary settings in WordPress as well.)

0
0

Try this:

RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
</IfModule>
# END WordPress

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.