CodeIgniterでindex.phpを消すためのmod_rewrite設定 @さくらのレンタルサーバ その2


CodeIgniterでindex.phpを消すためのmod_rewrite設定 @さくらのレンタルサーバ その2

下記の記事に対して、

CodeIgniterでindex.phpを消すためのmod_rewrite設定 @さくらのレンタルサーバ – 第2.5地区

Kenjiさんが別の方法を提案されていたので試してみたところ、

この方法でもうまくいきました。

さくらのレンタルサーバでの CodeIgniter の .htaccess 設定 – A Day in Serenity @ Kenji

.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?__PATH_INFO__=$1 [L,QSA]

Config クラスを拡張

CodeIgniter 1.7では

system/application/libraries/MY_Config.php

CodeIgniter 2.0では

system/application/core/MY_Config.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Config extends CI_Config {
function __construct()
{
parent::__construct();
if (isset($_GET['__PATH_INFO__']))
{
$_SERVER['PATH_INFO'] = $_GET['__PATH_INFO__'];
unset($_GET['__PATH_INFO__']);
$this->set_item('uri_protocol', 'PATH_INFO');
}
}
}
  • このエントリーをはてなブックマークに追加

コメントをどうぞ

メールアドレスが公開されることはありません。