Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess codeigniter 2 htaccess路由差异_.htaccess_Codeigniter_Apache2_Codeigniter 2 - Fatal编程技术网

.htaccess codeigniter 2 htaccess路由差异

.htaccess codeigniter 2 htaccess路由差异,.htaccess,codeigniter,apache2,codeigniter-2,.htaccess,Codeigniter,Apache2,Codeigniter 2,28日发布的Codeigniter v2.0。我刚刚安装了一个新的安装,并试图从url中删除index.php。我使用的是相同的apache站点可用配置、htaccess和codeigniter配置 当我排除index.php时,Codeigner仅加载routes.php中定义的默认控制器 比如说 将加载欢迎控制器 将加载欢迎控制器 但将加载事件控制器 这是我对该站点的apache配置 <VirtualHost *:80> ServerAdmin webmaster@local

28日发布的Codeigniter v2.0。我刚刚安装了一个新的安装,并试图从url中删除index.php。我使用的是相同的apache站点可用配置、htaccess和codeigniter配置

当我排除index.php时,Codeigner仅加载routes.php中定义的默认控制器

比如说

  • 将加载欢迎控制器
  • 将加载欢迎控制器
  • 但将加载事件控制器
这是我对该站点的apache配置

<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>

服务器管理员webmaster@localhost
ServerName myurl.com
DocumentRoot/var/www/myurl.com
选项如下符号链接
AllowOverride文件信息
选项索引跟随符号链接多视图
AllowOverride文件信息
命令允许,拒绝
通融
ScriptAlias/cgi-bin//usr/lib/cgi-bin/
不允许超限
选项+执行CGI-多视图+符号链接所有者匹配
命令允许,拒绝
通融
ErrorLog/var/log/apache2/error.log
#可能的值包括:调试、信息、通知、警告、错误、临界值、,
#警惕,埃默格。
日志级别警告
CustomLog/var/log/apache2/access.log组合
别名/doc/“/usr/share/doc/”
选项索引多视图跟随符号链接
不允许超限
命令拒绝,允许
全盘否定
允许从127.0.0.0/255.0.0.0::1/128开始

这是我的htaccess配置

<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

重新启动发动机
重写基/
#删除用户对系统文件夹的访问权限。
#此外,这将允许您创建System.php控制器,
#以前这是不可能的。
#如果已重命名系统文件夹,则可以替换“系统”。
重写COND%{REQUEST_URI}^系统*
重写规则^(.*)$/index.php?/$1[L]
#当应用程序文件夹不在系统文件夹中时
#此代码段阻止用户访问应用程序文件夹
#提交人:Fabdrol
#将“应用程序”重命名为应用程序文件夹名称。
重写cond%{REQUEST_URI}^应用程序*
重写规则^(.*)$/index.php?/$1[L]
#检查用户是否试图访问有效文件,
#例如图像或css文档,如果这不是真的,它会发送
#请求index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L]
#如果我们没有安装mod_rewrite,所有404
#可以发送到index.php,一切正常。
#提交人:ElliotHaughin
ErrorDocument 404/index.php

下面是找到的codeigniter配置文件/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'] = '';

我发现,将路由类型从AUTO更改为REQUEST\u URI使一切正常

 $config['uri_protocol']   = 'AUTO';


RewriteRule^(.*)$/index.php/$1[L](不带问号)?当涉及到uri_协议时,所有主机都是不同的,因此当您的URL出现错误并且您确定这不是您的.htaccess规则时,我建议每个人都使用uri_协议值。我曾经遇到过这样的问题:PATH_INFO的值只在某些服务器上有效,而AUTO的值主要在其他服务器上有效。REQUEST_URI是我的MAMP localhost上的必需值。似乎与以前的CI版本不同:(我真的很喜欢以前的CI版本,我可以将uri_协议设置为AUTO,它几乎可以在任何地方工作。现在我必须在测试/生产服务器上处理不同的配置值。不那么方便…:(对我来说,它与更改为
PATH\u INFO
有关。我现在使用2.0.3。在1.7.3中,它与
AUTO
有关。)。。。
 $config['uri_protocol']   = 'REQUEST_URI';