thewzrdharry
thewzrdharry

Reputation: 1

Wordpress site htaccess not redirecting to https when manually entering URL starting with http

I've made changes to my htaccess file on my WordPress site to redirect traffic from http to https.

Most cases it works fine and redirects traffic to https, but some cases it doesn't.

For example, if I try access home page with http in address it redirects to https, but if I try and access another page on the site with http in URL it stays on http:

Current htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>

RewriteEngine On

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

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

RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
</IfModule>
# END WordPress

I've tried numerous answers in other question, what else can I try?

Upvotes: 0

Views: 1673

Answers (5)

Dominic.tech
Dominic.tech

Reputation: 5

I had the same problem, and the fix was really simple... Just be sure to put the https redirection BEFORE the original rewrite code of Wordpress...

Exemple :

# Redirection code (redirect no www to www and http to https)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com$
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R=301,L]
</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>

Upvotes: 0

Nigel B
Nigel B

Reputation: 3597

Change your site address in Settings: enter image description here

and add the code below at the top of WordPress’ .htaccess file.

  1. RewriteEngine on
  2. RewriteCond %{HTTP_HOST} ^yoursite.com [NC,OR]
  3. RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
  4. RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301,NC]

Upvotes: 0

Pawan Thakur
Pawan Thakur

Reputation: 591

It will work for www and https

# BEGIN WordPress
<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>
# END WordPress

Upvotes: 0

Br&#233;nt Russęll
Br&#233;nt Russęll

Reputation: 784

Why do you have the following at the bottom? What happens when you remove this? I think this may be conflicting with RewriteCond %{HTTPS} off at the top. What happens when you remove this...

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

Upvotes: 0

usman ikram
usman ikram

Reputation: 445

try this

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

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

Upvotes: 0

Related Questions