【问题标题】:Subdirectory Issue with CodeIgniterCodeIgniter 的子目录问题
【发布时间】:2012-12-20 15:48:31
【问题描述】:

我在主域 (domain.com) 上安装了 CodeIgniter 应用程序。现在我想使用一个博客目录 (domain.com/blog/),我想在其中安装一个 WordPress 驱动的博客。但问题是我创建了一个名为博客的目录,但是当我尝试通过键入 domain.com/blog/ 来访问它时,我得到 CodeIgniter 404 not fount page。我对 CodeIgniter 很陌生,所以我一定在这里遗漏了一些东西。

谢谢

【问题讨论】:

    标签: php codeigniter directory codeigniter-2


    【解决方案1】:

    假设您使用.htaccess 从您的网址中删除index.php,您应该在项目的根目录中有一个.htaccess,其中包含以下内容:

    RewriteCond $1 !^(index\.php|robots\.txt|css|images)
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    基本上是说“将所有请求发送到index.php/$request,除非它们以index.phprobots.txtcssimages 开头”。

    这样您就不必使用像 http://example.com/index.php/controller/method 这样的 URL。

    只需添加blog:

    RewriteCond $1 !^(index\.php|robots\.txt|css|images|blog)
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    【讨论】:

    • 但万一他没有使用重写引擎。他可以添加一个子域:)
    • OP 必须使用 mod_rewrite 否则它不会显示 Codeigniter 404。
    • 即使不使用 .htaccess 也可以获得 404 - 试试吧!!
    • 它不会加载 Codeigniter 404,除非请求被路由到 Codeigniter 引导文件,通常是 index.php。 “Codeigniter 404”表示请求已由 CI 处理,但未找到匹配的路由或调用了 show_404()
    • 是的。但这并不意味着您应该为此使用重写引擎
    猜你喜欢
    • 1970-01-01
    • 2013-05-17
    • 1970-01-01
    • 1970-01-01
    • 2010-11-19
    • 1970-01-01
    • 1970-01-01
    • 2021-05-08
    • 1970-01-01
    相关资源
    最近更新 更多