Home  >  Article  >  php教程  >  Nginx configuration CodeIgniter project (1)

Nginx configuration CodeIgniter project (1)

黄舟
黄舟Original
2016-12-20 12:01:361814browse

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 (m.sbmmt.com)!


Statement:
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