这是28日公布的codeigniter V2.0。我只是设置一个新的安装,并试图从URL中删除的index.php。我现在用的是同一个Apache站点可用的配置,htaccess的,和codeigniter配置。
codeignter只加载在routes.php文件规定,当我排除的index.php默认的控制器。
例如
http://myurl.com/welcome 将加载欢迎控制器 http://myurl.com/events 将加载欢迎控制器 但 http://myurl.com/index.php/events 将加载事件控制器下面是我对网站的问题Apache的配置。
<虚拟主机*:80>
的ServerAdmin网站管理员@本地
服务器名myurl.com
DocumentRoot的/var/www/myurl.com
<目录/>
有FollowSymLinks
设置AllowOverride FileInfo的
< /目录>
<目录/var/www/myurl.com>
选择了FollowSymLinks指标多视图
设置AllowOverride FileInfo的
订购允许,拒绝
允许所有
< /目录>
的ScriptAlias / cgi-bin目录/ / usr / lib目录/ cgi-bin目录/
<目录/ usr / lib目录/ cgi-bin目录>
设置AllowOverride无
选项+ ExecCGI -MultiViews + SymLinksIfOwnerMatch
订购允许,拒绝
所有允许
< /目录>
错误日志/var/log/apache2/error.log
#可能的值包括:调试,信息,通知,警告,错误,暴击,
#警觉,EMERG。
日志级别警告
的CustomLog /var/log/apache2/access.log结合
别名/ DOC /的/ usr /共享/ DOC /
<目录的/ usr /共享/ DOC />
选择多视图索引了FollowSymLinks
设置AllowOverride无
订单拒绝,允许
所有拒绝
从127.0.0.0/255.0.0.0允许:: 1/128
< /目录>
下面是我的htaccess的配置。
< IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteBase /
#Removes用户访问到系统文件夹。
#Additionally这将允许您创建一个System.php控制器,
#previously这将是不可能。
#'系统'可以,如果你已重命名系统文件夹进行更换。
的RewriteCond%{REQUEST_URI} ^系统。*
重写规则^(。*)$ /index.php?/$1 [L]
#当你的应用程序文件夹没有在系统文件夹
#这个片断prevents用户到应用程序文件夹的访问
Fabdrol:由#Submitted
#Rename'应用'为您的应用程序文件夹名称。
的RewriteCond%{REQUEST_URI} ^应用。*
重写规则^(。*)$ /index.php?/$1 [L]
#Checks,查看是否用户正在试图访问一个有效的文件,
#such作为图像或CSS文档,如果这不是它发送的真实
#request的index.php
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$的index.php?/ $ 1 [L]
< / IfModule>
<!IfModule mod_rewrite.c>
#如果我们没有mod_rewrite的安装,所有404的
#可以被发送到index.php,一切工作正常。
#提交者:ElliotHaughin
的ErrorDocument 404的index.php
和这里是我的codeigniter配置文件中找到/var/www/mysite.com/application/config/config.php
< PHP的,如果(定义(BASEPATH')!)出口('没有直接的脚本允许访问);
/ *
| ------------------------------------------------- -------------------------
|基地网站网址
| ------------------------------------------------- -------------------------
|
|网址到codeIgniter根。通常情况下,这将是你的基地址,
|以斜线:
|
| http://example.com/
|
|如果没有设置,那么codeIgniter会猜测该协议,域和
|路径安装。
|
* /
$配置['BASE_URL'] ='mysite.com';
/ *
| ------------------------------------------------- -------------------------
|索引文件
| ------------------------------------------------- -------------------------
|
|通常情况下,这将是你的index.php文件,除非你已经重新命名为
|别的东西。如果您使用mod_rewrite删除设置此页
|变量,以便它是空白的。
|
* /
$配置['index_page'] ='';
/ *
| ------------------------------------------------- -------------------------
| URI协议
| ------------------------------------------------- -------------------------
|
|此项目决定哪些服务器全球应该用来检索
| URI字符串。 AUTO的默认设置适用于大多数的服务器。
|如果您的链接似乎不工作,尝试其他美味的口味之一:
|
| AUTO默认 - 自动检测
| 'PATH_INFO'使用PATH_INFO
| 'QUERY_STRING'使用QUERY_STRING
| REQUEST_URI采用REQUEST_URI
| ORIG_PATH_INFO采用ORIG_PATH_INFO
* /
$配置['uri_protocol'] ='自动';
/ *
| ------------------------------------------------- -------------------------
| URL后缀
| ------------------------------------------------- -------------------------
|
|这个选项允许你添加一个后缀由codeIgniter生成的所有URL。
|欲了解更多信息,请参阅用户指南:
|
| HTTP://$c$cigniter.com/user_guide/general/urls.html
* /
$配置['url_suffix才能'] ='';
解决方案
我发现,改变从自动路由类型REQUEST_URI使一切工作。
$配置['uri_protocol'] ='自动';
到
$配置['uri_protocol'] ='REQUEST_URI';
Codeigniter v2.0 that was released on the 28th. I just setup a fresh installation and tried to remove the index.php from the url. I am using the same apache site-available configuration, htaccess, and codeigniter configuration.
Codeignter only loads the default controller defined in routes.php when I exclude the index.php.
For example
http://myurl.com/welcome will load the welcome controller http://myurl.com/events will load the welcome controller but http://myurl.com/index.php/events will load the events controllerHere is my apache configuration for the site in question.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName myurl.com
DocumentRoot /var/www/myurl.com
<Directory />
Options FollowSymLinks
AllowOverride FileInfo
</Directory>
<Directory /var/www/myurl.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride FileInfo
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
Here is my htaccess configuration
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
And here is my codeigniter configuration file found /var/www/mysite.com/application/config/config.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
$config['base_url'] = 'mysite.com';
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';
/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string. The default setting of 'AUTO' works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO' Default - auto detects
| 'PATH_INFO' Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI' Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
*/
$config['uri_protocol'] = 'AUTO';
/*
|--------------------------------------------------------------------------
| URL suffix
|--------------------------------------------------------------------------
|
| This option allows you to add a suffix to all URLs generated by CodeIgniter.
| For more information please see the user guide:
|
| http://codeigniter.com/user_guide/general/urls.html
*/
$config['url_suffix'] = '';
解决方案
I found that changing the routing type from AUTO to REQUEST_URI made everything work.
$config['uri_protocol'] = 'AUTO';
to
$config['uri_protocol'] = 'REQUEST_URI';