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
Jump without www to www

    RewriteCond% {http_host} ^demo.com [NC]
    RewriteRule ^(.*)$ Http://www.demo.com/$1 [L, R = 301]
1
2
3
4
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
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
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. . .





💘 相关文章


📝 有偿服务

• 服务器合租380/年
• 服务器配置:2.4G,6核12线程
• nvme raid 1硬盘
• 不提供服务器自主面板
• 适合稳定的个人博客
• 提供备份服务,备份空间自备
• 只提供ipv6地址,搭配cloudflare使用
• 提供想要安装的程序和域名
• 博客必须是和谐健康的
• 博客不能是视频和图片站
• 提供以下付费服务
• 建站,FTP,备份,Linux,Wordpress等建站问题咨询管理
• 加微信:344452500(不闲聊,直接说事)

写一条评论

Based on Golang + fastHTTP + sdb | go1.16.8 Processed in 0ms