Redirect HTTP to HTTPS in .htaccess

If you want to redirect HTTP to HTTPS and want to add www with each URL, use the htaccess below:

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

It will first redirect HTTP to HTTPS and then it will redirect to https://www

😉


Fatal error: Uncaught Error: Class "DOMDocument" not found in /home/nciaari7/public_html/wp-content/plugins/shortpixel-image-optimiser/class/Model/FrontImage.php:67 Stack trace: #0 /home/nciaari7/public_html/wp-content/plugins/shortpixel-image-optimiser/class/Model/FrontImage.php(41): ShortPixel\Model\FrontImage->loadImageDom() #1 /home/nciaari7/public_html/wp-content/plugins/shortpixel-image-optimiser/class/Controller/Front/CDNController.php(568): ShortPixel\Model\FrontImage->__construct() #2 /home/nciaari7/public_html/wp-content/plugins/shortpixel-image-optimiser/class/Controller/Front/CDNController.php(366): ShortPixel\Controller\Front\CDNController->extractImageMatches() #3 [internal function]: ShortPixel\Controller\Front\CDNController->processFront() #4 /home/nciaari7/public_html/wp-includes/functions.php(5493): ob_end_flush() #5 /home/nciaari7/public_html/wp-includes/class-wp-hook.php(341): wp_ob_end_flush_all() #6 /home/nciaari7/public_html/wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters() #7 /home/nciaari7/public_html/wp-includes/plugin.php(522): WP_Hook->do_action() #8 /home/nciaari7/public_html/wp-includes/load.php(1308): do_action() #9 [internal function]: shutdown_action_hook() #10 {main} thrown in /home/nciaari7/public_html/wp-content/plugins/shortpixel-image-optimiser/class/Model/FrontImage.php on line 67