user3325858
user3325858

Reputation: 15

Using htaccess to redirect http to https for Wordpress?

I've correctly enabled HTTPS redirect with the code below. After visiting one of the HTTPS pages, all other urls are inheriting the previous HTTPS. How can I force all other pages to HTTP?

# BEGIN WordPress
<IfModule mod_rewrite.c>

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} ^(/checkout|/downloads|/all-products)
RewriteRule ^(.*)$ https://websitename.com/$1 [R,L]

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

Upvotes: 0

Views: 833

Answers (1)

anubhava
anubhava

Reputation: 784878

You can use:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/(checkout|downloads|all-products)
RewriteRule ^(.*)$ https://websitename.com/$1 [R=301,L,NE]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/(checkout|downloads|all-products)
RewriteRule ^(.*)$ http://websitename.com/$1 [R=301,L,NE]

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

Upvotes: 1

Related Questions