ci框架裏rewrite示例

ci裏新建應用app,入口文件app.php。php

Nginx

這裏附上vhost配置css

app.52fhy.com.confnginx

server {
    listen       80;
    server_name  app.52fhy.com;
    index app.php;
    root /www/test/ci/;
    
    location ~ .*\.(php|php5)?$
    {
        #fastcgi_pass  unix:/tmp/php-cgi.sock;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index app.php;
        include fastcgi.conf;
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires 30d;
    }
    
    location ~ .*\.(js|css)?$
    {
        expires 1h;
    }

    location / {
      if (!-e $request_filename) {
                rewrite ^/(.*)$ /app.php?/$1 last;
                break;
          }
    }
    
    access_log  /www/log/nginx/access/app.52fhy.com.log;
}

nginx重啓命令爲:apache

/usr/local/nginx/sbin/nginx -s reload

url訪問示例:app

http://app.52fhy.com/Test/hello

實際url爲url

http://app.52fhy.com/app.php/Test/hello

實現了隱藏入口文件的功能。unix

Apache

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ /app.php/$1 [QSA,PT,L]
</IfModule>
相關文章
相關標籤/搜索