CodeIgniter 后端 前端 .htaccess 路由器
我正在尝试使用 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...)
- backend
- codeigniter
- [...] (cache, database, scaffolding...)
- application
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过更多搜索后,我发现了 非常好的文章记录了如何做我需要的事情。它还解释了 CI 中后端/前端的 3 种方法:
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:
HMVC fits my needs perfectly, but i'll give a try to sub-directories first. :)
基本上,您希望并排运行两个 CodeIgniter 应用程序,一个在根目录中,一个在
backend/
中。有几种方法可以做到这一点,但最简单的是为第二个实例添加重写规则(删除Last 标志):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):