Augus
Augus

Reputation: 495

Setup .htacces for non-ww and with ssl on multi domain

I have been looking all around the web but can't find a clean solution. Im not an hero in .htaccess rules but i would love to have some rules that will force the user to https and non-www for all the domains on that server / installation.

Atm i got this but im stuck;

# 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} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
</IfModule>

Upvotes: 1

Views: 54

Answers (1)

anubhava
anubhava

Reputation: 785551

Try this code:

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

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,R=301,L]

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

Also make sure WP permalink has https and non-www URL in site and home URLs.

Upvotes: 1

Related Questions