简体   繁体   中英

Redirect https://example.com to https://www.example.com

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.

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]

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]

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> 

Try this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM