Force "https" and "www" redirect
I am trying to see if there is a way to redirect url to https://www.example.com For example, if people are entering the url http://ift.tt/1gosCeT, then it should redirect to http://ift.tt/2cfJt6Z.
This is a Wordpress website. If I go to Settings => General => I see WordPress Address(URL) and Site Address (URL) are grayed out so I can't enter any url. Both shows as http://example.com
I went to phpMyAdmin=> option table to change the WordPress Address (URL) and Site Address (URL) to https://www.example.com but I still see the http://example.com on my wordpress general setting panel.
I looked at the wp-config file and found the following code that appears to be preventing me from entering custom url.
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_CONTENT_URL', '/wp-content');
define('DOMAIN_CURRENT_SITE', $_SERVER['HTTP_HOST']);
It seems like the WordPress Address(URL) and Site Address(URL) are enforced by the codes here.
My hosting provider recommanded using htaccess to enforce the ssl by putting the code below:
#Force SSL on entire site
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://(YOURDOMAIN)/$1 [R,L]
But this guide doesn't really tell us how to enforce www as well.
I found another guide here .htaccess - how to force "www." in a generic way? that explains how to enforce domain.com to www.domain.com. This one supposedly also check https and implement to the rewrite rule.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Now, someone else is recommanding the following code below, claiming that the first one above will only work if you want all sub-domains forwarded to www.yourdomain.com. I am just confused which one I need to choose?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I am trying to see which option would be the best solution to implement the force redirect? Or should I get rid of those four define() codes from wp-config file so I can setup redirect with wordpress general setting?
Aucun commentaire:
Enregistrer un commentaire