CI在Nginx服务器上rewrite去掉index.php例子
去掉index.php小编以前也有介绍过相关的文章了,在此小编再给各位介绍一篇CI在Nginx服务器上rewrite去掉index.php例子,希望下文可以帮助到大家。
CI框架在nginx服务器上配置rewrite去掉index.php的方法:
vim /usr/local/webserver/nginx/conf/nginx.conf
实例配置代码:
server { listen 80; server_name www.phprm.com; index index.html index.htm index.php; root /data0/htdocs/lamp100; #nginx去掉index.php location / { rewrite ^/$ /index.php last; rewrite ^/(?!index.php|robots.txt|uploadedImages|resource|images|js|css|styles|static)(.*)$ /index.php/$1 last; } #nginx模拟pathinfo,否则CI框架的控制器无法访问 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; }
以上都是自己实际中在使用的。【关于$document_root可能出现file not found的话,就把那个直接换成网站的root根路径】
补充: apache配置rewrite规则,删除url中的index.php
1,在httpd.conf文件中配置如下部分
<VirtualHost *:81> DocumentRoot D:/Source/v5 </VirtualHost> 改成 <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]
意思将所有http://domain/app/controller 的url重写为 http://domain/index.php/app/controller。
L(last rule) 表明当前规则是最后一条规则,停止分析以后规则的重写。
NC(no case) 不区分大小写。
2,重写规则既可以在apache配置里写,还可以在kohana的.htaccess文件里写。
另外在项目目录下面的conf/routes.php中也可以配置url替换规则。
IIS使用ISAPI_Rewrite配置httpd.ini在URL中去掉index.php
因为国内互联网应用服务提供商提供的服务器软件很多都是IIS,此处主要对IIS下使用httpd.ini配置文件去掉index.php进行介绍,如下方法经过验证:
1、修改项目配置文件"项目路径Confconfig.php",确保URL_MODEL设置为2。
2、配置httpd.ini,配置示例如下:
[ISAPI_Rewrite] # 3600 = 1 hour CacheClockRate 3600 RepeatLimit 32
#如下为关键的地方,示例中Public、Rbac/Tpl/Admin/Public 下都有一些图片、CSS文件,如果不做排除,那么网页不能正常显示。如果您希望排除更多的目录,请在如下代码中增加,增加格式为(?!目录路径)。
RewriteRule /(?!Public)(?!Rbac/Tpl/Admin/Public)(.*) /index.php/$1 [L]
文章地址:http://www.phprm.com/frame/81194.html
转载随意^^请带上本文地址!