Home php教程 PHP开发 Nginx configuration CodeIgniter project (1)

Nginx configuration CodeIgniter project (1)

Dec 20, 2016 pm 12:01 PM

First of all, I used Nginx’s URL rewrite method.

Turn on enable_query_strings

The method to turn on is very simple: set in application/config/config.php:

$config['enable_query_strings'] = FALSE;

The PATH_INFO mode used in CI development projects must be in To rewrite the URL in the Nginx configuration, you need to enable string query in the CI configuration file and compare the changes in the URL form:

URL: www.xxx.com/user/profile String query mode: www.xxx.com /index.php?c=user&m=profile

After rewriting the front-end and back-end URLs according to certain rules, the test was OK. But there is a problem when paging, because the paging URL address generated after enabling string query has changed:

Not enabled: /user/list/10 After enabling string query: /user/list&per_page=10

The reason why the following wrong URL appears is that when I generate pagination, the base_url format has not changed, so after changing from /user/list to the corresponding /index.php?c=user&m=list, it will become the following situation:

The second page: www.xxx.com/index.php?c=user&m=list&per_page=10 The third page: www.xxx.com/index.php?c=user&m=list&per_page=20 The fourth page: www.xxx .com/index.php?c=user&m=list&per_page=30

And the pagesize I set is always 10, so per_page should always be 10. I took a look at the code of the Pagination class and found that per_page is just the default value of query_string_segment. I mistakenly thought it was the per_page parameter.

Paging is compatible with rewrite

To summarize, if paging is to be compatible with rewrite, then change the base_url parameter when generating paging:

Method 1: /index.php?c=user&m=list, the result is: /index.php?c=user&m=list&per_page=10 Method 2: /user/list?, the result is: /user/list?&per_page=10

The paging SQL is:

$this->db-> ;limit($pagesize, $this->input->get('per_page'));

In order to maintain URL consistency, we still use the second method. You can also add any useless parameters later to get the result. Becomes /user/list?x=xxx&per_page=10.

Discuss

about pagination. Of course, you can also not use the paging that comes with CI, or change Pagination.php.

If it is passed as a parameter of method, a normal URL such as: /user/arg1/arg2/arg3, then it cannot be passed during rewrite (at least I haven’t found a solution yet). If you want to The solution is unless the parameters are passed in GET mode, which requires changing the program, so it is not recommended.

And using rewrite requires targeting different forms of URLs, which becomes a burden if the project is complex, so I looked for another method: let Nginx pass PATH_INFO to fastcgi, see the next article.

The above is the content of Nginx configuration CodeIgniter project (1). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement custom middleware in CodeIgniter How to implement custom middleware in CodeIgniter Jul 29, 2023 am 10:53 AM

How to implement custom middleware in CodeIgniter Introduction: In modern web development, middleware plays a vital role in applications. They can be used to perform some shared processing logic before or after the request reaches the controller. CodeIgniter, as a popular PHP framework, also supports the use of middleware. This article will introduce how to implement custom middleware in CodeIgniter and provide a simple code example. Middleware overview: Middleware is a kind of request

CodeIgniter middleware: Accelerate application responsiveness and page rendering CodeIgniter middleware: Accelerate application responsiveness and page rendering Jul 28, 2023 pm 06:51 PM

CodeIgniter Middleware: Accelerating Application Responsiveness and Page Rendering Overview: As web applications continue to grow in complexity and interactivity, developers need to use more efficient and scalable solutions to improve application performance and responsiveness. . CodeIgniter (CI) is a lightweight PHP-based framework that provides many useful features, one of which is middleware. Middleware is a series of tasks that are performed before or after the request reaches the controller. This article will introduce how to use

Nginx error page configuration, beautify website failure prompts Nginx error page configuration, beautify website failure prompts Jul 04, 2023 pm 01:33 PM

Nginx error page configuration, beautify website fault prompts. During the operation of the website, it is inevitable to encounter server errors or other faults. These problems will cause users to be unable to access the website normally. In order to improve user experience and website image, we can configure Nginx error pages to beautify website failure prompts. This article will introduce how to customize the error page through Nginx's error page configuration function, and provide code examples as a reference. 1. Modify the Nginx configuration file. First, we need to open the Nginx configuration.

How to use the database query builder (Query Builder) in the CodeIgniter framework How to use the database query builder (Query Builder) in the CodeIgniter framework Jul 28, 2023 pm 11:13 PM

Introduction to the method of using the database query builder (QueryBuilder) in the CodeIgniter framework: CodeIgniter is a lightweight PHP framework that provides many powerful tools and libraries to facilitate developers in web application development. One of the most impressive features is the database query builder (QueryBuilder), which provides a concise and powerful way to build and execute database query statements. This article will introduce how to use Co

PHP development: Using CodeIgniter to implement MVC pattern and RESTful API PHP development: Using CodeIgniter to implement MVC pattern and RESTful API Jun 16, 2023 am 08:09 AM

As web applications continue to evolve, it is important to develop applications more quickly and efficiently. And, as RESTful API is widely used in web applications, it is necessary for developers to understand how to create and implement RESTful API. In this article, we will discuss how to implement MVC pattern and RESTful API using CodeIgniter framework. Introduction to MVC pattern MVC (Model-Vie

How to use CodeIgniter5 framework in php? How to use CodeIgniter5 framework in php? Jun 01, 2023 am 11:21 AM

CodeIgniter is a lightweight PHP framework that uses MVC architecture to support rapid development and simplify common tasks. CodeIgniter5 is the latest version of the framework and offers many new features and improvements. This article will introduce how to use the CodeIgniter5 framework to build a simple web application. Step 1: Install CodeIgniter5 Downloading and installing CodeIgniter5 is very simple, just follow these steps: Download the latest version

CodeIgniter middleware: Provides secure file upload and download functions CodeIgniter middleware: Provides secure file upload and download functions Aug 01, 2023 pm 03:01 PM

CodeIgniter middleware: Provides secure file upload and download functions Introduction: In the process of web application development, file upload and download are very common functions. However, for security reasons, handling file uploads and downloads often requires additional security measures. CodeIgniter is a popular PHP framework that provides a wealth of tools and libraries to support developers in building secure and reliable web applications. This article will introduce how to use CodeIgniter middleware to implement secure files

How to implement Nginx cross-origin resource sharing (CORS) configuration How to implement Nginx cross-origin resource sharing (CORS) configuration Nov 08, 2023 pm 12:22 PM

How to implement Nginx's cross-domain resource sharing (CORS) configuration requires specific code examples. With the popularity of front-end and back-end separation development, cross-domain resource sharing (CORS) issues have become a common challenge. In web development, due to the browser's same-origin policy restrictions, client-side JavaScript code can only request resources with the same domain name, protocol, and port as the page where it is located. However, in actual development, we often need to request resources from different domain names or different subdomains. At this time, you need to use CO

See all articles