Mobile app version of vmapp.org
Login or Join
Ravi8258870

: .htaccess doesn't redirect my pages from HTTP to HTTPS It seems like .htaccess doesn't redirect my pages from http to https. My domain is redirected to https but not my pages… Can it be

@Ravi8258870

Posted in: #301Redirect #Htaccess #Https #Redirects #Seo

It seems like .htaccess doesn't redirect my pages from http to https.
My domain is redirected to https but not my pages… Can it be a bad configuration from my web host?

Here is what I have done until now:


Choose a SSL certificate and installed it on my website from the host.
Force wp-config to pass from HTTP to HTTPs with: define('FORCE_SSL_ADMIN', true);
Tranform all of my URLs to HTTPs with Replace and Search DB
Add this domain to Google Search Console…


Put this code in my .htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect to HTTPS
RewriteCond %{HTTP_HOST} ^http://example.com [NC]
RewriteCond %{SERVER_PORT} ^80$ [OR]
RewriteCond %{HTTPS} =off [OR]
RewriteRule ^(.*)$ example.com/ [L,R=301]
# Redirect from www HTTPS to HTTPS
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ example.com/ [L,R=301]

RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>


I think that's all… Would you have an idea of what can cause this problem?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Ravi8258870

1 Comments

Sorted by latest first Latest Oldest Best

 

@Jamie184

RewriteCond %{HTTP_HOST} ^http://example.com [NC]



The HTTP_HOST variable contains just the hostname, not the scheme + hostname, so this will never match. If this never matches then it will never redirect example.com/... to HTTPS. (However, you have used this correctly in your second rule block which will redirect www.example.com/... to HTTPS.)

I assume you only have one domain? In which case, that directive should simply be removed (not corrected).


RewriteCond %{HTTPS} =off [OR]



However, you also have an erroneous OR flag on the last RewriteCond directive. If the preceding condition(s) matched then this would result in a redirect loop, since it's essentially <condition> OR true, which is always true.

Summary


# Redirect to HTTPS
RewriteCond %{HTTP_HOST} ^http://example.com [NC]
RewriteCond %{SERVER_PORT} ^80$ [OR]
RewriteCond %{HTTPS} =off [OR]
RewriteRule ^(.*)$ example.com/ [L,R=301]



So, in summary, you should replace the first rule block (above) with the following:

# Redirect to HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ example.com/ [L,R=301]


There's no point checking both SERVER_PORT and HTTPS. Either should be sufficient; not both.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme