【发布时间】:2012-05-19 09:51:20
【问题描述】:
Codeigniter 应用程序通常使用 mod_rewrite 从 url 中排除字符串 index.php。我在同一个域中有两个 Codeigniter 应用程序。一个 Codigniter 应用程序位于 web 根文件夹中,另一个 Codigniter 应用程序位于 web 根文件夹的子文件夹中。
Codeigniter 应用程序 1:
http://domain.com/index.php
Codeigniter 应用 2(登陆页面应用):
http://domain.com/land/index.php
这两个 Codeigniter 应用程序都是原子的,它们之间不共享任何文件。 Codeigniter 框架中的每个文件都在public_html/ 和public_html/land/ 中。所以我需要在寻址根/ 文件夹的url 中排除字符串index.php,并在/land/ 子文件夹中排除字符串index.php。
根文件夹中的 .htaccess 文件使用来自 Codeigniter wiki 的广泛推荐的 mod_rewrite 规则(代码如下),这组规则适用于根 Codeigniter 应用程序(应用程序 1)。这些规则位于 web 根文件夹中。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#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
#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 %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 /index.php
</IfModule>
上述规则集在根 Codeigniter 应用程序中从 url 中删除 index.php 没有问题。但是这套规则似乎不允许public_html/land/.htaccess中的mod_rewrite规则执行。
当我删除 public_html/.htaccess 中的 mod_rewrite 规则时,public_html/land/.htaccess 中的 mod_rewrite 规则开始被评估。
有没有办法更改 public_html/.htaccess 中的 mod_rewrite 规则以处理旨在访问 /land/ 子文件夹的 url 的特殊情况?
我认为最好的解决方案可能是更改 public_html/.htaccess 中的 mod_rewrite 规则,以允许在 url 中处理子文件夹时执行 public_html/land/.htaccess 中的 mod_rewrite 规则。我愿意接受任何建议。
先发制人地回答“为什么不使用子域?”这个问题1. 在 SSL 证书上省钱。 2) 非技术用户有时会对营销基础域名的子域感到困惑。
先发制人地回答“为什么不将 Codeigniter 应用程序结合起来使用框架中的相同文件?”复制框架文件是保持版本存储库分离的一种简单方法。
【问题讨论】:
-
将文件夹添加到 RewriteBase,如:RewriteBase /land/
标签: apache .htaccess mod-rewrite codeigniter-url