ci框架里rewrite示例

ci里新建应用app,入口文件app.php。

Nginx

这里附上vhost配置

app.52fhy.com.conf

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重启命令为:

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

url访问示例:

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

实际url为

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

实现了隐藏入口文件的功能。

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>
原文地址:https://www.cnblogs.com/52fhy/p/5061314.html