admin avatar

3 ways to implement domain name jump to www including https using 301

🕓 by admin

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. . .

1
2
3
4
http jump https

    RewriteCond% {SERVER_PORT}! ^443$
    RewriteRule (.*) Https://%{SERVER_NAME} /$1 [R = 301, L]

1
2
3
4
5
Jump without www to www

    RewriteCond% {http_host} ^demo.com [NC]
    RewriteRule ^(.*)$ Http://www.demo.com/$1 [L, R = 301]

1
2
3
4
5
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

1
2
3
4
5
6
7
server {
listen 80;
server_name www.example.org example.org;
if ($ http_host = example.org) {
rewrite (.*) http://www.example.org$1;
}

Code 2

1
2
3
4
5
6
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. . .

💘 相关文章

写一条评论