Add the following to your htaccess file! Remember to edit it for your domain name.
# Force url with WWW
RewriteBase /
RewriteCond %{HTTP_HOST} !^site.com$ [NC]
RewriteRule ^(.*)$ http://www.site.com/$1 [L,R=301]
# Force https
RewriteCond %{HTTP_HOST} ^site\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.site.com/$1 [R,L]
Hope this helps! Let us know if you have any problems!
Thank for the reply. When I applied the code on my htaccess file, and reloaded my home page, I am getting the following error code.
The http://www.site.com page isn’t working
http://www.site.com redirected you too many times.
Try:
Reloading the page
Clearing your cookies
ERR_TOO_MANY_REDIRECTS
Please read my message again. it is not as simple as just copying that code. Your url is not site.com. you need to change all instances of site.com to have your url.
For instance, my url is dehnavi.net so my code would look like this
# Force url with WWW
RewriteBase /
RewriteCond %{HTTP_HOST} !^dehnavi.net$ [NC]
RewriteRule ^(.*)$ http://www.dehnavi.net/$1 [L,R=301]
# Force https
RewriteCond %{HTTP_HOST} ^dehnavi\.net [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.dehnavi.net/$1 [R,L]
Please note: I do not have a site up at that address but that is the code I would use if I wanted to do what you are trying to do.