教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 CI在Nginx服务器上rewrite去掉index.php例子

CI在Nginx服务器上rewrite去掉index.php例子

发布时间:2023-05-10   编辑:jiaochengji.com
教程集为您提供CI在Nginx服务器上rewrite去掉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.111cn.net;
    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、修改项目配置文件"项目路径\Conf\config.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]

您可能感兴趣的文章:
php runtime、http web中rewrite浅解和方案
lighttpd配置url重写一例
ubuntu隐藏index.php的方法
php运行在什么服务器上?
ThinkPHP利用.htaccess文件的Rewrite规则隐藏URL中的index.php
PHP路由浅析 php中URL路由的实现思路
Zendframework登陆注册实例详解
PHP与nginx之间的运行机制及其原理
Linux高可用(HA)之Heartbeat Nginx MySQL NFS实现WEB SQL服务高可用
php结合nginx实现动态裁剪图片

[关闭]
~ ~