CodeIgniter 后端 前端 .htaccess 路由器

发布于 2024-08-10 16:54:46 字数 1102 浏览 7 评论 0原文

我正在尝试使用 CodeIgniter 开发一个小的基础 CMS 供我自己在项目中使用,但陷入了困境。另外,我对 CI 很陌生,但已经使用了 ZF 和 OOP PHP 一些年了。

首先让我向您展示我的文件结构:

  • index.php(前端引导)
  • backend.php(后端引导)
  • .htaccess
  • 系统(CI 核心)
    • 申请
      • 后端
        • [...]MVC 相关文件和文件夹(配置、控制器、模型、视图...)
      • 前端
        • [...]MVC 相关文件和文件夹(配置、控制器、模型、视图...)
    • 代码点火器
    • [...](缓存、数据库、脚手架...)

好的。我可以使用 .htaccess 来使用 index.php 或 backend.php 路由,但无法让它同时使用两者。这是 .htaccess 代码:

RewriteEngine on
RewriteBase /

# Hide the application and system directories by redirecting the request to index.php (and throwing a 404 error)
RewriteRule ^(application|system|\.svn) index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

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

嗯,我需要的是以下内容:

  • www.domain.com/backend/controller/action/parameters (backend.php 路由)
  • www.domain.com/controller/action/parameters (index.php 路由)

希望我解释得很好。

有人可以帮忙吗? :)

此致。

I'm trying to develop a little base CMS with CodeIgniter for my own use on projects but got stuck on this. Also, I'm very new to CI, but got some years with ZF and OOP PHP.

First of all let me show you my file structure:

  • index.php (frontend bootstrap)
  • backend.php (backend bootstrap)
  • .htaccess
  • system ( CI core )
    • application
      • backend
        • [...] MVC related files and folders (config, controllers, models, views...)
      • frontend
        • [...] MVC related files and folders (config, controllers, models, views...)
    • codeigniter
    • [...] (cache, database, scaffolding...)

Ok. I can get to work the index.php or backend.php routing with an .htaccess, but can't get it to work with both. Here's the .htaccess code:

RewriteEngine on
RewriteBase /

# Hide the application and system directories by redirecting the request to index.php (and throwing a 404 error)
RewriteRule ^(application|system|\.svn) index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

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

Well, what I need is the following:

  • www.domain.com/backend/controller/action/parameters (backend.php routing)
  • www.domain.com/controller/action/parameters (index.php routing)

Hope I explained well.

Can anyone help, please? :)

Best regards.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

煮茶煮酒煮时光 2024-08-17 16:54:46

经过更多搜索后,我发现了 非常好的文章记录了如何做我需要的事情。它还解释了 CI 中后端/前端的 3 种方法:

  • 单独的应用程序
  • 子目录
  • HMVC(分层模型视图控制器)

HMVC 完全满足我的需求,但我会首先尝试子目录。 :)

After some more searching, I've found a very nice article documenting how to do what I need. It also explains the 3 ways to backend/frontend in CI:

  • separate applications
  • sub-directories
  • HMVC (Hierarchical Model View Controller)

HMVC fits my needs perfectly, but i'll give a try to sub-directories first. :)

顾冷 2024-08-17 16:54:46

基本上,您希望并排运行两个 CodeIgniter 应用程序,一个在根目录中,一个在 backend/ 中。有几种方法可以做到这一点,但最简单的是为第二个实例添加重写规则(删除Last 标志):

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

Basically you want to run two CodeIgniter applications side by side, one in the root and one in backend/. There are a few ways to do this, but the simplest is to add a rewrite rule for your second instance (removing the Last flag):

RewriteRule ^backend/(.*)$ /backend/index.php/$1 [QSA]
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文