【问题标题】:mod-rewrite problem in codeignitercodeigniter中的mod-rewrite问题
【发布时间】:2010-12-06 10:10:20
【问题描述】:

我正在我的本地主机(Usbwebserver 应用程序)上开发一个站点。我正在使用 CodeIgniter 框架:

网址是“http://localhost/daniel/index.php

有以下选项:

配置/路由:

$route['default_controller'] = "site";

配置/配置:

$config['base_url'] = "http://localhost/daniel";
$config['index_page'] = "";
$config['uri_protocol'] = "REQUEST_URI";

我尝试了以下 .htaccess 代码:

重写引擎开启 重写基础/

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

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

# 如果我们没有安装 mod_rewrite,所有 404 的 # 可以发送到 index.php,一切正常。 # 提交人:ElliotHaughin

ErrorDocument 404 /index.php

我想删除 index.php 并使用 http://localhost/daniel 加载我的默认控制器。

有什么建议吗?

【问题讨论】:

    标签: .htaccess mod-rewrite codeigniter


    【解决方案1】:

    试试:

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

    【讨论】:

    • 我已经尝试过了,我认为它有效,我的意思是 localhost/daniel/site 在 index.php 上重定向了我。但是它显示了由 CodeIgniter 生成的 404 Page Not Found。我在 index.php 的开头添加了一个回显,它回显正确。认为codeigniter设置有问题。 (差点忘了说我的应用程序文件夹在系统文件夹之外)
    • 愚蠢的问题,但您确实有一个名为“站点”的控制器,对吧?
    • 我刚刚以某种方式修复了它。我不知道到底是什么问题
    【解决方案2】:

    我使用了 codigniter wiki 中的 hataccess(与上面相同):

    重写引擎开启 重写基础/

    # Removes the "/" at the end
    RewriteRule (.+)/$ /$1 [L,R]
    
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ daniel/index.php?/$1 [L]
    

    # 如果我们没有安装 mod_rewrite,所有 404 的 # 可以发送到 index.php,一切正常。 # 提交人:ElliotHaughin

    ErrorDocument 404 /index.php
    

    使用所有相同的选项,只有 $config['uri_protocol'] = "AUTO"(而不是 URI_PROTOCOL)和 它开始工作了(而且我在系统之外有应用程序文件夹文件夹)

    感谢所有热情回复我的人!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多