Example of removing index. php from rewrite of CI on Nginx server

Source: Internet
Author: User

The CI framework configures rewrite on the nginx server to remove index. php:

Vim/usr/local/webserver/nginx/conf/nginx. conf
Instance configuration code:

Server
  {
Listen 80;
Server_name www.111cn.net;
Index index.html index.htm index. php;
Root/data0/htdocs/lamp100;
 
# Remove index. php from nginx
Location /{
Rewrite ^/$/index. php last;
 
Rewrite ^ /(?! Index \. php | robots \. txt | uploadedImages | resource | images | js | css | styles | static) (. *) $/index. php/$1 last;
    }
 
# Nginx simulates pathinfo, otherwise the controller of the CI framework cannot be accessed
 
Location ~ ^ (. + \. Php) (. *) $
    {
 
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_split_path_info ^ (. + \. php) (. *) $;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Fastcgi_param PATH_INFO $ fastcgi_path_info;
Fastcgi_param PATH_TRANSLATED $ document_root $ fastcgi_path_info;
Include fastcgi_params;
 
    }
 
Log_format lamp100logs '$ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" $ http_x_forwarded_for ';
Access_log/data1/logs/lamp100logs. log lamp100logs;
 
  }
 

All of the above are actually in use. [If file not found may appear in $ document_root, replace it with the root path of the website]

Supplement: apache configures rewrite rules to delete index. php from the url.

1. Configure the following parts in the httpd. conf file:

<VirtualHost *: 81>
DocumentRoot D:/Source/v5
</VirtualHost>

Change

<VirtualHost *: 81>
DocumentRoot D:/Source/v5
# Turn on URL rewriting
RewriteEngine On
 
<Span style = "white-space: pre"> </span> RewriteRule ^/app/(. *) $/index. php/app/$1 [L, NC]
<Span style = "white-space: pre"> </span> RewriteRule ^/api/(. *) $/index. php/api/$1 [L, NC]
<Span style = "white-space: pre"> </span> RewriteRule ^/open/(. *) $/index. php/open/$1 [L, NC]
<Span style = "white-space: pre"> </span> RewriteRule ^/admin/(. *) $/index. php/admin/$1 [L, NC]
</VirtualHost>

RewriteRule ^/app/(. *) $/index. php/app/$1 [L, NC]

Rewrite the URLs of all http: // domain/app/controller to http: // domain/index. php/app/controller.
L (last rule) indicates that the current rule is the last rule. After the analysis is stopped, the rule is overwritten.
NC (no case) is case insensitive.
2. Rewrite rules can be written both in apache configuration and in the. htaccess file of kohana.
In addition, you can configure url replacement rules in conf/routes. php under the Project Directory.


IIS uses ISAPI_Rewrite to configure httpd. ini to remove index. php from the URL

Because many of the server software provided by Internet application service providers in China is IIS, The following describes how to remove index. php from the httpd. ini configuration file in IIS:
1. Modify the project configuration file "Project path \ Conf \ config. php" to make sure that URL_MODEL is set to 2.
2. Configure httpd. ini as follows:
[ISAPI_Rewrite]
#3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# The following is the key. In this example, Public, Rbac, Tpl, Admin, and Public files all have images and CSS files. If they are not excluded, the webpage cannot be properly displayed. If you want to exclude more directories, add them in the following code. The format is (?! Directory path ).
RewriteRule /(?! Public )(?! Rbac/Tpl/Admin/Public) (. *)/index. php/$1 [L]

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.