nginx ci index.php,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文件中配置如下部分

DocumentRoot D:/Source/v5

改成

DocumentRoot D:/Source/v5

# Turn on URL rewriting

RewriteEngine On

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

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

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

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

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]

转载随意^^请带上本文地址!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值