2012-05-10 108 views
0

中从Codeigniter中删除index.php Codeigniter应用程序通常使用mod_rewrite从url中排除字符串index.php。我在同一个域中有两个Codeigniter应用程序。一个Codigniter应用程序位于Web根文件夹中,另一个Codigniter应用程序位于Web根文件夹的子文件夹中。mod_rewrite在子目录

笨应用1:

http://domain.com/index.php 

笨应用2(着陆页的应用程序):

http://domain.com/land/index.php 

两个笨的应用是每个原子,不把它们之间共享任何文件。 Codeigniter框架中的每个文件都在public_html/中,并且再次在public_html/land/中。所以我需要在网址/的文件夹中排除字符串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规则来处理打算访问/land/子文件夹的URL的特殊情况?

我认为最好的解决方案可能是更改public_html/.htaccess中的mod_rewrite规则,以允许在url中寻址子文件夹时执行public_html/land/.htaccess中的mod_rewrite规则。我愿意接受任何建议。

对“为什么不只是使用子域?”这个问题的先发制人的答案。 1.节省SSL证书的费用。 2)非技术用户有时会被子域名混淆用于营销基本域名。

对“为什么不将Codeigniter应用程序结合使用以在框架中使用相同的文件?”的先发性回答?复制框架文件是保持版本存储库分离的简单方法。

+0

将该文件夹添加到RewriteBase中,如下所示:RewriteBase/land/ – Drewdin

回答

1

在顶部添加一条规则,如果它是请求字符串的一部分,则转到land子文件夹。这样,/land/.htaccess中的规则将被执行,而不是/.htaccess中的后续规则。所以把这个顶部:

RewriteRule ^land.*$ - [NC,L] 

这将检查该请求是否与“土地”开始,它重定向到子目录,其中对应于该子目录的.htaccess规则将被代替使用。

现有的规则检查文件和文件夹,而不是在请求对应其中一个时进行重写的原因是因为请求中的任何后续“land”可能都不是真实文件,因此重写规则会触发。

+0

这不适用于我。我在'public_html/.htaccess'的规则顶部添加了该行,但是'public_html/land/.htaccess'不会执行。我通过故意在'public_html/land/.htaccess'中导致服务器错误进行了测试,但.htaccess文件从未运行,并且没有服务器错误。只是一个404错误。 – steampowered

+0

404错误很奇怪 - 它应该至少找到一些东西加载在土地subdir的权利?你可以添加一个规则来记录重写并检查日志吗? RewriteLog“/usr/local/apache/logs/rewrite.log” RewriteLogLevel 4 并确保日志文件夹和文件存在并可由Web服务器写入。 – Ansari

+0

这是一个很好的建议来记录重写。谢谢! – steampowered

1

的问题是在public_html/.htaccess的规则重写URL的要/land/,你需要一个直通这使得它使没有任何反应时/land/是requested.Add:

RewriteRule ^land/ - [L] 

你的规则其余部分之前。

+0

这对我不起作用。我在'public_html/.htaccess'的规则顶部添加了行,但'public_html/land/.htaccess'不会执行。我通过故意在'public_html/land/.htaccess'中导致服务器错误进行了测试,但.htaccess文件从未运行,并且没有服务器错误。只是一个404错误。 – steampowered