大多数用php实现的应用, 都是单一入口, 即把所有对该应用的请求, 对转发到入口文件(index.php, app.php)等,
把所有请求都转发到单一入口, 有利于面向对象php框架的设计, 也有利于URL美化。 上面的那个URL肯定是不要index.php的好看多了吧
如nginx的请求转发
location {
if (!-e $request_filename ){
rewrite ^/(.*) /app.php?$1 last;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
以上nginx的配置就是把所有请求都转发到app.php
apache的配置
Apache常用.htaccess文件来重写URL
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
以上Apache配置吧所有请求转发到index.php