Codeigniter应用程序通常使用mod_rewrite从url中排除字符串index.php。我在同一个域中有两个Codeigniter应用程序。一个Codigniter应用程序位于web根文件夹中,另一个Codigniter应用程序位于web根文件夹的子文件夹中。
Codeigniter应用程序1:
http://domain.com/index.phpCodeigniter应用程序2(登录页面应用程序):
http://domain.com/land/index.php 这两个Codeigniter应用程序都是原子的,它们之间不共享任何文件。Codeigniter框架中的每个文件都是public_html/格式的,也是public_html/land/格式的。因此,我需要在寻址根/文件夹的urls中排除字符串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应用程序的urls中删除index.php没有任何问题。但是这组规则似乎不允许执行public_html/land/.htaccess中的mod_rewrite规则。
当我删除public_html/.htaccess中的mod_rewrite规则时,将开始评估public_html/land/.htaccess中的mod_rewrite规则。
有没有办法改变public_html/.htaccess中的mod_rewrite规则来处理url访问/land/子文件夹的特殊情况?
我认为最好的解决方案可能是更改public_html/.htaccess中的mod_rewrite规则,以便当子文件夹在url中被寻址时,执行public_html/land/.htaccess中的mod_rewrite规则。我乐于接受任何建议。
抢先回答“为什么不直接使用子域?”1.节省SSL证书的费用。2)非技术用户在营销基础域名时,有时会被子域所迷惑。
抢先回答“为什么不组合Codeigniter应用程序以在框架中使用相同的文件?”复制框架文件是保持版本控制存储库分离的一种简单方法。
发布于 2012-05-11 03:05:26
在顶部添加一个规则,以便仅转到land子文件夹(如果它是请求字符串的一部分)。这样,将执行/land/.htaccess中的规则,而不是/.htaccess中的后续规则。所以把这个放在最上面:
RewriteRule ^land.*$ - [NC,L]这将检查请求是否以'land‘开头,并将其重定向到子目录,在那里将应用与该子目录相对应的.htaccess规则。
现有规则检查文件和文件夹,如果请求对应于其中一个,则不执行重写的原因是因为请求中“land”后面的内容可能不是真正的文件,因此重写规则将触发。
发布于 2012-05-11 03:09:44
问题是public_html/.htaccess中的规则重写了指向/land/的URL,你需要一个通过,这样当/land/为requested.Add时不会发生任何事情:
RewriteRule ^land/ - [L]在你剩下的规则之前。
https://stackoverflow.com/questions/10540524
复制相似问题