1

How can I redirect my website from https://example.com to https://www.example.com

My website is not working in non www. need to redirect to https://www.example.com format. Please help me in this.

Nataraj
  • 852
  • 2
  • 14
  • 29

4 Answers4

0

One way would be to ask your DNS provider for a redirect.

Another way gets explained in this other stackoverflow question: .htaccess - how to force "www." in a generic way? Basically the following should work:

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

Community
  • 1
  • 1
spitterfly
  • 28
  • 1
  • 4
0

To redirect your site from http non-www to https://www you can use the following rule :

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS} off 
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,R]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
0

If you're using apache as your website, you can use alias

<VirtualHost *:443>
    ServerName www.example.com
    ServerAlias example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/devops_blog
    <Directory /var/www/devops_blog>
        Options All
        AllowOverride All
        Require all granted
    </Directory>
DennyZhang
  • 342
  • 2
  • 7
0

Try this

RewriteEngine on
RewriteCond %{HTTPS_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L] 
Ketan Borada
  • 856
  • 9
  • 24