当前位置:网站首页>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 !️
边栏推荐
- Is Guotai Junan Futures safe? How to open a futures account? How to reduce the futures commission?
- 存在安全隐患 路虎召回部分混动揽运
- Snowflake algorithm implemented in go language
- [go] runtime package for concurrent programming and its common methods
- #夏日挑战赛# HarmonyOS - 实现带日期效果的待办事项
- Istio FAQ: sidecar startup sequence
- Bitwise Operators
- TRTC web end imitation Tencent conference microphone mute detection
- AI structured intelligent security video monitoring technology, supporting the protective umbrella of the reserve / wild animals
- 【prometheus】1. Monitoring overview
猜你喜欢

B. Terry sequence (thinking + greed) codeforces round 665 (Div. 2)

Cap: multiple attention mechanism, interesting fine-grained classification scheme | AAAI 2021

Problems encountered in the work of product manager

【面试高频题】难度 3/5,可直接构造的序列 DP 题
![[download attached] installation and simple use of Chinese version of awvs](/img/3b/f26617383690c86edff465c9a1099e.png)
[download attached] installation and simple use of Chinese version of awvs

Ps\ai and other design software pondering notes

Ui- first lesson

Some adventurer hybrid versions with potential safety hazards will be recalled

存在安全隐患 路虎召回部分混动揽运

Wechat official account debugging and natapp environment building
随机推荐
2021-04-25: given an array arr and a positive number m, the
国泰君安期货安全么?期货开户怎么开?期货手续费怎么降低?
Istio FAQ: sidecar startup sequence
@There is a free copyright protection service for enterprises in Dawan District
How to open a futures account safely? Which futures companies are more reliable?
[go] runtime package for concurrent programming and its common methods
Video structured intelligent analysis platform easycvr video recording plan function optimization / regularly delete expired videos
Transpose convolution explanation
Global and Chinese market of training dance clothes 2022-2028: Research Report on technology, participants, trends, market size and share
mysql时间戳格式转换日期格式字符串
ZOJ——4104 Sequence in the Pocket(思维问题)
How to pop up an alarm through the national standard gb28181 protocol video platform easygbs for mobile detection / perimeter intrusion detection video recording
Istio FAQ: sidecar stop sequence
Golang+redis reentrant lock
MySQL日期时间戳转换
MySQL Advanced Series: locks - locks in InnoDB
Global and Chinese market of music synthesizer 2022-2028: Research Report on technology, participants, trends, market size and share
Comparison of jmeter/k6/locust pressure measuring tools (not completed yet)
Heavy release! Tencent cloud ASW workflow, visual orchestration cloud service
SQL multi table updating data is very slow