首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于从子目录中的Codeigniter中删除index.php的mod_rewrite

问用于从子目录中的Codeigniter中删除index.php的mod_rewrite
EN

Stack Overflow用户
提问于 2012-05-11 02:59:28
回答 2查看 5.8K关注 0票数 1

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

Codeigniter应用程序1:

代码语言:javascript
复制
http://domain.com/index.php

Codeigniter应用程序2(登录页面应用程序):

代码语言:javascript
复制
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根文件夹中。

代码语言:javascript
复制
<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应用程序以在框架中使用相同的文件?”复制框架文件是保持版本控制存储库分离的一种简单方法。

EN

回答 2

Stack Overflow用户

发布于 2012-05-11 03:05:26

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

代码语言:javascript
复制
RewriteRule ^land.*$ - [NC,L]

这将检查请求是否以'land‘开头,并将其重定向到子目录,在那里将应用与该子目录相对应的.htaccess规则。

现有规则检查文件和文件夹,如果请求对应于其中一个,则不执行重写的原因是因为请求中“land”后面的内容可能不是真正的文件,因此重写规则将触发。

票数 1
EN

Stack Overflow用户

发布于 2012-05-11 03:09:44

问题是public_html/.htaccess中的规则重写了指向/land/的URL,你需要一个通过,这样当/land/为requested.Add时不会发生任何事情:

代码语言:javascript
复制
RewriteRule ^land/ - [L]

在你剩下的规则之前。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10540524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档