この投稿は?
Phalcon PHPの開発環境を整える際のルーティングスクリプトまとめです。
よくあるMVCフレームワークならほぼそのまま流用できるんじゃないかな。
今はApache, PHP Built-in webserver, IISのみ。
追記していくかもしれないし、しないかもしれません。
wwwサーバごとのルーティングスクリプト一覧
Apache | PHP Built-in webserver | IIS | |
---|---|---|---|
routing | .htaccess | .router.php | web.config |
project直下 | ○ | ○ | ○ |
public直下 | ○ | - | ○ |
Apache
構成
[projectディレクトリ]
public/.htaccess : (1)
.htaccess : (2)
中身
(1)
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
(2)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
適用方法
mod_rewriteが有効だったら何もしなくてOK
PHP Built-in webserver
構成
[projectディレクトリ]
.router.php : (1)
中身
(1)
<?php
if (!file_exists(__DIR__ . '/' . $_SERVER['REQUEST_URI'])) {
$_GET['_url'] = $_SERVER['REQUEST_URI'];
}
return false;
参考:http://docs.phalconphp.com/en/latest/reference/built-in.html
適用方法
[projectディレクトリ]で
php -S localhost:80 -t public .router.php
としてbuilt-inサーバを起動
http://localhost/
にアクセスしてやればOK。
IIS
構成
[projectディレクトリ]
public/web.config : (1)
web.config : (2)
中身
(1)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?_url=/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
(2)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Public Rule 1" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="public/" />
</rule>
<rule name="Public Rule 2" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="public/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
適用方法
IISマネージャーで物理パス(=DocumentRoot)として [projectディレクトリ]/public が設定されていれば、
特に何もしなくていいはず。#間違っていたらごめんなさい