codeigniter 2 htaccess 路由差异 [英] codeigniter 2 htaccess routing differences

查看:22
本文介绍了codeigniter 2 htaccess 路由差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 仅在排除 index.php 时加载在 routes.php 中定义的默认控制器.

Codeignter only loads the default controller defined in routes.php when I exclude the index.php.

例如

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

这是我对相关站点的 apache 配置.

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

这是我的 htaccess 配置

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

这是我找到的 codeigniter 配置文件/var/www/mysite.com/application/config/config.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'] = '';

推荐答案

我发现将路由类型从 AUTO 更改为 REQUEST_URI 使一切正常.

I found that changing the routing type from AUTO to REQUEST_URI made everything work.

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

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

这篇关于codeigniter 2 htaccess 路由差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆