For websites with an architecture like LNMP, they are generally developed based on PHP frameworks. PHP frameworks generally pay attention to elegant links. For example, Laravel, CodeIgniter, ThinkPHP, etc. all support this link mode, which is also called URL rewriting in server configuration. At present, most frameworks use a single entry index.php and then based on the MVC mode, it is generally a request method of /index.php/Model/function. Therefore, if the index.php entry file can be removed, the entire URL will appear simple and beautiful, and the URL mode of websites developed in Python, Java, etc. will be unified. Apache and nginx both support this URL mode. The following is a description of the nginx configuration method. First, enter the installation directory of nginx. In the previous article, we mentioned that in the configuration file nginx.conf, there is a code segment such as server {} to specify the configuration of a site. There are many other configurations below. We add the following code to the corresponding server {} code segment in the configuration file or the included configuration file to implement URL rewriting: location / { try_files $uri $uri/ /index.php?$query_string; } If the original location / {} code already exists, then just append the line of code in the figure, because the configuration of the same route is usually put together; after saving, restart the nginx server to take effect. If nginx is added to the service, you can use /etc/init.d/nginx restart to restart it. After restarting, the URL will be beautified. There is another way to rewrite the URL on the Internet. Add the following code in the same location to solve it: location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } } After saving, restart nginx to take effect, and you can also achieve the effect of URL beautification. However, according to some articles on the Internet, the first method is recommended for URL beautification. 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:
|
<<: JavaScript implements the pot-beating game of Gray Wolf
>>: Descending Index in MySQL 8.0
Table of contents illustrate 1. Blob object 2. Fr...
We all know that the underlying data structure of...
The function I want to achieve is to open a new w...
Table of contents 1. Introduction to autofs servi...
Preface: The Linux host is relatively easy to han...
Checkboxes are very common on web pages. Whether ...
Table of contents Inheritance and prototype chain...
First, let me briefly introduce what MySQL is; In...
Step 1: Configure environment variables (my decom...
1. Text around the image If we use the normal one...
In addition to B-Tree indexes, MySQL also provide...
I don't know if it's because the binary d...
This article shares the specific code of JavaScri...
Table of contents 1. Picture above 2. User does n...
1. Installation process MySQL version: 5.7.18 1. ...