当前位置:网站首页>Popular explanation [redirection] and its practice
Popular explanation [redirection] and its practice
2022-06-24 16:25:00 【Programmer fish skin】
Three minutes , Take you to learn and practice domain name redirection
Hello everyone , I'm fish skin , Share today Redirect Little knowledge , And my practice of domain name redirection in Tencent cloud development .
Evil rise
Before , I developed a programming navigation website , Put the website on Tencent cloud development , Cloud hosting ( Containers ) The way to deploy and maintain . And bought a domain name code-nav.cn, And in the background of cloud development Access the service in , The subdomain name of the domain name www.code-nav.cn Associated with the container where the website files are stored , Configuration is shown in figure :
then , You can go through the website www.code-nav.cn Visit the website .
however , Soon , I found a serious problem .
Many students want to visit my website , however , Because the URL they entered is code-nav.cn, Omit the URL prefix www, Make the website inaccessible . Also let me lose a batch of users .
first battle —— Domain name configuration
To solve this problem , It's very simple , Before that was configuration www Subdomains point to containers , Then add another configuration in the background of cloud development , Directly purchase the domain name ( Parent domain name )code-nav.cn It also points to the container , That's it ?
The configuration is as follows :
such , Whether or not the user enters www Prefix , Can visit our website !
It seems perfect , But at the moment, , There are still some problems with the website .
Existing problems
First , belt www With or without www It's actually two different websites , Although for users , It feels like visiting the same website . But for search engines , Spiders will identify them as two different websites , And respectively include the content of the website under these two paths , It leads to weight dispersion . Although it has little influence on websites with small traffic , But for big sites , This is a problem that has to be dealt with .
Besides , visit code-nav.cn( No www) The user response , The data on the website could not be loaded . This is because , Tencent developed WEB Secure domain name restrictions , Only domain names in the white list are allowed to access cloud resources ( data 、 Documents, etc. ), therefore , Still in Security configuration in , Fill up code-nav.cn domain name .
Although it's normal now , But if there are still some and www The logic of strong correlation of websites , For example, it is necessary to judge that the URL visited by the user must be www.code-nav.cn To log in , Then you have to modify the code , A little thoughtless , It will lead to some functional problems .
To solve these problems , We can use Redirect technology .
Redirect
Redirection is a very broad concept , That is to say, through various methods, all kinds of network requests are reoriented to other locations , Like web redirection 、 Domain redirection 、 Data packet redirection, etc .
In website development , There are too many scenarios for redirection , For example, when the user is not logged in , The URL it entered will automatically jump to the login page ; When users visit the old web address , Automatically jump to the new page . Redirection is not just a tour guide , And an overbearing security guard .
therefore , Many large sites will use redirection Technology . Like visiting Baidu baidu.com, Press F12 Check out the developer console , You can see the URL through 302 Redirect , Auto jump to www.baidu.com.
That's the question , What is 302 Redirect ?
Take a look at common redirections HTTP Status code .
Redirect HTTP Status code
About redirection HTTP The status code is mainly 301、302、303、307、308, The most common is 301 and 302, You can see MDN The official interpretation of them .
301 Is a permanent redirect (Moved Permanently) Indicates that the requested resource has been permanent Moved to by Location Head designated url On , It's fixed it won't change , The search engine will correct... Based on the response .
and 302 It's a temporary transfer (Moved Temporarily, perhaps Found), Indicates that the requested resource is temporary Moved to by Location Head designated URL On . The browser will redirect to this URL, However, the search engine will not update the link of this resource .
although 301 and 302 Can input the user's web address A, Change to reset the backward URL B, But they are different :
- The difference between search engines :301 It means the original address A The resource for has been removed , Never have access to , When search engine grabs content, it will send URL A Replace all with B; and 302 It's a web address A Still alive , Search engines will be crawling websites B New content at the same time , Keep the URL A The record of .
- Security :302 Jump has the risk of website hijacking , Leading to website embezzlement .
Fight again —— Cloud development redirection practice
After learning about redirection , Let's try how to achieve redirection , And how to implement domain name redirection in cloud development .
There are many ways to achieve redirection , A lot depends on what you use web The server , such as Nginx、Apache、Tomcat etc. , Generally, you can add several configurations to the server .
My programming navigation website is in a container way , Deployed on the cloud hosting function provided by cloud development . I put the developed website file and provide web Service Nginx The servers are packaged together , Made into containers , therefore , You can think of each container as a small server , Independent operation .
To support redirection , Just change it Nginx Configuration of . For example, here I choose to add 301 Permanent redirection , The configuration file is as follows :
server {
listen 80;
# gzip config
gzip on;
...
root /usr/share/nginx/html;
include /etc/nginx/mime.types;
# Add redirection
if ($http_host ~ "^code-nav.cn") {
rewrite ^(.*) https://www.code-nav.cn permanent;
}
}No need to write and remember Nginx To configure , Directly use the visual interface to generate :
See this article for details : Easy to handle Nginx Configuration code artifact !
Other server configurations are also available in the documentation , No more details here .
then , Create a new version on cloud hosting , Release a new container , That's it !
Check the effect , visit code-nav.cn, The site has been redirected to www.code-nav.cn, perfect !
summary
Last , Review the whole process of domain name redirection in Tencent cloud development , It includes the following steps :
- stay
Access the serviceAdd the parent domain name to the site ( Cloud hosting, etc ) - stay
Security configurationAdd the parent domain name to the whitelist - stay web Add redirection configuration to the server
- New version , Deployment of release
The whole process is very simple ~
If this article is helpful , Please do give me a Fabulous Support !️
边栏推荐
- Several characteristics of pharmaceutical industry
- 嵌入式开发基础之线程间通信
- My network relationship with "apifox"
- A memory leak caused by timeout scheduling of context and goroutine implementation
- MySQL日期时间戳转换
- The million bonus competition is about to start, and Ti-One will be upgraded to help you win the championship!
- 2021-05-01: given an ordered array arr, it represents the points located on the X axis. Given a positive number k
- Join in ABAP CDs
- Object store signature generation
- 【应用推荐】最近大火的Apifox & Apipost 上手体验与选型建议
猜你喜欢

存在安全隐患 部分冒险家混动版将召回

【面试高频题】难度 3/5,可直接构造的序列 DP 题

构建Go命令行程序工具链

Siggraph 2022 | truly restore the hand muscles. This time, the digital human hands have bones, muscles and skin

Problems encountered in the work of product manager

Using oasis to develop a hop by hop (I) -- Scene Building

How to easily realize online karaoke room and sing "mountain sea" with Wang Xinling
MySQL Advanced Series: Locks - Locks in InnoDB

C. Three displays(动态规划)Codeforces Round #485 (Div. 2)

Wechat official account debugging and natapp environment building
随机推荐
Inter thread communication of embedded development foundation
Install the imagemagick7.1 library and the imageick extension for PHP
Build go command line program tool chain
[tke] modify the cluster corendns service address
Is Shanjin futures safe? What are the procedures for opening futures accounts? How to reduce the futures commission?
Pytorch 转置卷积
Go deep into the implementation principle of go language defer
微信公众号调试与Natapp环境搭建
2021-05-04: given a non negative integer C, you need to judge whether there are two integers a and B, so that a*a+b*b=c.
MD5 verification based on stm32
Some experiences of project K several operations in the global template
Global and Chinese market of insect proof clothing 2022-2028: Research Report on technology, participants, trends, market size and share
60 divine vs Code plug-ins!!
mysql时间戳格式转换日期格式字符串
[tke] troubleshooting tips for container problems
MySQL日期时间戳转换
April 26, 2021: the length of the integer array arr is n (3 < = n < = 10^4), and each number is
2021-04-27: if the adjacent position of a character does not have the same character
Global and Chinese market of training dance clothes 2022-2028: Research Report on technology, participants, trends, market size and share
Flink kubernetes application deployment