3 ways to implement domain name jump to www including https using 301
Have deep obsessive-compulsive disorder
Just like domain name with www
Without www, I feel uncomfortable. . . .
The first is to use a .htaccess file to implement the jump
.htaccess file uses apache server and litespeed / openlitespeed
Here is the code. . .
http jump https
RewriteCond% {SERVER_PORT}! ^443$
RewriteRule (.*) Https://%{SERVER_NAME} /$1 [R = 301, L]
Jump without www to www
RewriteCond% {http_host} ^demo.com [NC]
RewriteRule ^(.*)$ Http://www.demo.com/$1 [L, R = 301]
With www jump to without www
RewriteCond% {http_host} ^www.demo.net [NC]
RewriteRule ^ (.*)$ Http://demo.net/$1 [L, R = 301]
Implementation of the second nginx platform
Code 1
server {
listen 80;
server_name www.example.org example.org;
if ($ http_host = example.org) {
rewrite (.*) http://www.example.org$1;
}
Code 2
server {
listen 80;
server_name example.org;
return 301 http://www.example.org$request_uri;
}
The third type is implemented by third-party platforms, such as cloudflare.com
Enter the domain name and find page rules
Add a rule to use a 301 redirect for the Forwarding URL, see the figure below. . .
