start learning
72

Htaccess WWW And https redirection

How to configure redirection for my domain ?

To redirect all requests for your website to use the www prefix and HTTPS, you can add the following code to your .htaccess file: First, create a file in your directory with the name .htaccess. After that, copy and paste the code from the text area below :


# Redirect non-www to www and HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$  [NC]
RewriteRule ^(.*)$ https://www.%1/$1 [L,R=301]

This code first checks if HTTPS is off or if the request is for a non-www domain. If either of these conditions is true, the code redirects the request to the HTTPS version of the www domain using a 301 redirect.

Note that you will need to have an SSL certificate installed on your server for HTTPS to work. Additionally, this code assumes that your website is hosted on an Apache server with the mod_rewrite module enabled.

click this link to Check if your ssl is correctly configured