Now more and more websites use SSL, which the URL start from “https”. We can set WordPress websites to use https by settings->general->WordPress Address (URL) & Site Address (URL) to “http://www.webdux.com”. But one problem is when visitor put http://www.webdux.com, the URL can’t redirect to “https”, so we can use .htaccess to redirect HTTP to HTTPs by followed code.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

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

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

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

The first red paragraph is for http to https and second red paragraph is for webdux.com to www.webdux.com (Tested for CentOS).

For some servers, such as Ubuntu, aboved http to https code may can’t work or have some problems, so you can use followed code:

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

Use folloed for webdux.com to www.webdux.com

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

In fact, the wordpress will add most code to .htaccess file, so we mainly add the red part code, the http will redirect HTTP to HTTPs.

0 Likes
443 Views

You may also like

Leave A Comment

Please enter your name. Please enter an valid email address. Please enter message.