8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WWWサーバごとのルーティングスクリプトまとめ@PhalconPHP編

Last updated at Posted at 2014-02-23

この投稿は?

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 が設定されていれば、
特に何もしなくていいはず。#間違っていたらごめんなさい

8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?