URL rewriting helps determine the preferred domain of the website. 301 redirects for multiple paths of the same resource page help to concentrate the URL weight. Introduction to Nginx URL Rewriting Like Apache and other web service software, the main function of rewrite is to redirect the URL address. Nginx's rewrite function requires the support of PCRE software, that is, rule matching is performed through perl-compatible regular expression statements. Compiling nginx with default parameters will support the rewrite module, but PCRE support is also required rewrite is the key instruction to implement URL rewriting. It redirects to replacement according to the regex (regular expression) part, and ends with a flag tag. The rewrite syntax format and parameter syntax are as follows: rewrite <regex> <replacement> [flag]; Keyword regular replacement content flag tag Keywords: The keyword error_log cannot be changed Regular: Perl compatible regular expression statement for rule matching Replacement content: Replace the content matched by the regular expression with replacement Flag tag: flag tag supported by rewrite Flag description:
The label segment position of the rewrite parameter: server,location,if example: rewrite ^/(.*) http://www.czlun.com/$1 permanent; illustrate:
regex Common regular expression description
rewrite Enterprise Application Scenarios Nginx's rewrite function is widely used in enterprises:
Introduction to Nginx rewrite configuration process (1) Create a rewrite statement vi conf/vhost/www.abc.com.conf #vi edit the virtual host configuration file File Contents server { listen 80; server_name abc.com; rewrite ^/(.*) http://www.abc.com/$1 permanent; } server { listen 80; server_name www.abc.com; location / { root /data/www/www; index index.html index.htm; } error_log logs/error_www.abc.com.log error; access_log logs/access_www.abc.com.log main; } or server { listen 80; server_name abc.com www.abc.com; if ( $host != 'www.abc.com' ) { rewrite ^/(.*) http://www.abc.com/$1 permanent; } location / { root /data/www/www; index index.html index.htm; } error_log logs/error_www.abc.com.log error; access_log logs/access_www.abc.com.log main; } (2) Restart the service After confirmation, you can restart. The operation is as follows: nginx -t #If the result shows ok and success, you can restart nginx -s reload (3) Check the jump effect Open your browser and visit abc.com After the page is opened, abc.com in the URL address bar becomes www.abc.com, indicating that the URL is rewritten successfully. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Summary of MySql import and export methods using mysqldump
>>: Common array operations in JavaScript
The automatic scrolling effect of the page can be...
The effect is as follows: The code is as follows ...
This article introduces how to monitor the ogg pr...
This article uses the deep learning framework ker...
This article example shares the specific code of ...
background nginx-kafka-module is a plug-in for ng...
1: Installation command pip install docker-compos...
Table of contents Creating OAuth Apps Get the cod...
Check what is installed in mysql rpm -qa | grep -...
Deploy redis in docker First install Docker in Li...
To do a paginated query: 1. For MySQL, it is not ...
Table of contents In JavaScript , there are sever...
1. Always close HTML tags In the source code of p...
1. Text around the image If we use the normal one...
This article shares the specific code of JavaScri...