【问题标题】:CI 2.0 controller/function access not workingCI 2.0 控制器/功能访问不起作用
【发布时间】:2011-02-11 05:54:47
【问题描述】:

我正在使用 CI 构建一个网站,我希望我的网站 URI 像

http://myweb.com/controller/function

没有'index.php'部分。

我已经成功地使用 CI 1.73 做到了这一点,但我无法使用 CI 2.0
我已将 route.php 设置为:

$route['default_controller'] = 'home';

和config.php

$config['index_page'] = '';

我还使用 CI 1.73 放置了在我的试用版中工作的 .htaccess 文件

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myweb

#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 $1 !^(index\.php|images|captcha|css|js|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

有什么建议吗?

【问题讨论】:

  • 记得说出你正在尝试什么以及实际发生了什么,而不仅仅是“不起作用”。

标签: .htaccess codeigniter codeigniter-url codeigniter-2


【解决方案1】:

我会说这条线RewriteBase /myweb 是罪魁祸首。尝试使用 RewriteBase / 代替。

另外,我会尽量简化你的 .htaccess,直到你让它工作,像这样:

<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

请注意,我认为您应该在 index.php 之后只放一个 /,而不是像这样的 ?/:

RewriteRule ^(.*)$ index.php/$1 [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 2019-08-23
    • 2015-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多