I'm running a Wordpress blog that has an issue with HTTPS redirect. Except home page, no other URL is being redirected to HTTPS if you visit via HTTP.
I want to redirect all HTTP traffic to HTTPS. Currently, only the Home page(http://www.example.com) is being redirected to HTTPS if you try with HTTP.
but if you visit http://www.example.com/page1, then it won't be redirected to HTTPS and stays at HTTP.
I don't want to use any plugin such as "really simple SSL". After a lil'bit of searching over net, I found that I can modify the .htaccess
file to do that. Then I tried to understand .htaccess file (considering I never worked with PHP or WordPress or even Apache before). I got to know that RewriteEngine On
should appear only once in your file but in my case, it's appearing twice. maybe some plugin or theme had modified this that i'm not aware of. below is the content of my .htaccess file.
# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 24 hours"
ExpiresByType image/jpeg "access plus 24 hours"
ExpiresByType image/gif "access plus 24 hours"
ExpiresByType image/png "access plus 24 hours"
ExpiresByType text/css "access plus 24 hours"
ExpiresByType application/pdf "access plus 1 week"
ExpiresByType text/javascript "access plus 24 hours"
ExpiresByType text/html "access plus 5 minutes"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 24 hours"
</IfModule>
<ifModule mod_headers.c>
Header set X-Endurance-Cache-Level "2"
</ifModule>
<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
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I don't have any subdomains. only a single domain. So to clear my doubts, I have two questions.
1) Is this .htaccess file correct? I mean can we have two RewriteEngine On
lines? that too outside the , again I'm not very familiar with this syntax.
2) What should I change to reflect HTTPS redirection on all of my pages?
Moreover, it also broke the Non-WWW to WWW redirection.
PS: these are one of the links that I have visited-
https://wordpress.org/support/article/htaccess/