Nginx CodeIgniter configuration project (1)

Source: Internet
Author: User
A recent project used Nginx as a WEB server. some problems encountered when deploying CI projects on Nginx may have been encountered or solved by many of my friends.

First, I use the Nginx URL rewrite method.

Enable_query_strings

The method for enabling is simple: Set in application/config. php:

$config['enable_query_strings'] = FALSE; 

In The PATH_INFO mode used in the CI development project, to rewrite the URL in the Nginx configuration, you must enable string query in the CI configuration file to compare the URL format changes:

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

After the front-end and back-end URLs are rewritten according to certain rules, the test is OK. However, there is a problem during paging because the pagination URL address generated after string query is enabled has changed:

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

The following error occurs: When I generate a page, the base_url format does not change. then, the URL changes from/user/list to the corresponding/index. php? C = user & m = list will become the following situation:

Page 2: www.xxx.com/index.php? C = user & m = list & per_page = 10 page 3: www.xxx.com/index.php? C = user & m = list & per_page = 20 page 4: www.xxx.com/index.php? C = user & m = list & per_page = 30

The pagesize I set is always 10, so per_page should always be 10. Let's take a look at the code of the Pagination class and find that per_page is only the default value of query_string_segment. I mistakenly thought it was the per_page parameter.

Paging compatible rewrite

To sum up the paging line, if you want to be compatible with the rewrite method, you can change the base_url parameter when generating the page:

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')); 

To maintain URL consistency, or use the second method, you can add useless parameters to convert the result to/user/list? X = xxx & per_page = 10.

Discussion
  • Paging. Of course, you can also change Pagination. php without using the built-in pages of CI.
  • If it is passed as a method parameter, the normal URL is:/user/arg1/arg2/arg3, in this case, you cannot pass the rewrite statement (at least I have not found a solution). to solve this problem, you must change the program unless you change the parameter to the GET method. Therefore, it is not recommended.
  • In addition, the use of rewrite should be targeted at different forms of URLs. if the project is complex, it will become cumbersome, so we seek another method: let Nginx pass PATH_INFO to fastcgi. see the next article.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.