Phalcon 在 Apache\Nginx以及 PHP 内置服务器下的重写规则
我们假设系统目录结构如下:
/path/to/app/
controllers/
models/
views/
public/
css/
js/
img/
index.php
index.php 为入口文件。
Apache
将 .htaccess 文件存放在 /path/to/app/public/ 目录下,同时编辑该文件,内容如下:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
一个完整的虚拟主机配置文件示例:
<VirtualHost *:80>
ServerAdmin admin@example.host
DocumentRoot "/path/to/app/public"
DirectoryIndex index.php
ServerName example.host
ServerAlias www.example.host
<Directory "/path/to/app/public">
Options All
AllowOverride All
Allow from all
</Directory>
</VirtualHost>
Nginx
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $app_root/public;
}
location ~ /\.ht {
deny all;
}
评论已关闭