mod_rewrite的从codeigniter在子目录中删除的index.php [英] mod_rewrite to remove index.php from Codeigniter in subdirectory

查看:249
本文介绍了mod_rewrite的从codeigniter在子目录中删除的index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

codeigniter应用程序通常使用mod_rewrite排除字符串的index.php 从URL。我有相同的域名中的两个codeigniter应用。一个Codigniter应用是Web根目录,另一个Codigniter应用是Web根目录下的子目录。

Codeigniter applications commonly use mod_rewrite to exclude the string index.php from the url. I have two Codeigniter applications within the same domain. One Codigniter application is in the web root folder, another Codigniter application is in a subfolder of the web root folder.

codeigniter应用1:

Codeigniter application 1:

http://domain.com/index.php

codeigniter申请2(登陆页面的应用程序):

Codeigniter application 2 (the landing page application):

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

这两个codeigniter应用程序是每一个原子,不把它们之间共享任何文件。在codeigniter框架中的每个文件是在的public_html / 又在的public_html /陆/ 。所以,我需要排除的URL处理根 / 文件夹中的字符串的index.php ,也排除字符串的index.php /陆/ 子文件夹。

The two Codeigniter applications are each atomic and do not share any files between them. Every file in the Codeigniter framework is in public_html/ and again in public_html/land/. So I need to exclude the string index.php in urls addressing the root / folder and also exclude the string index.php in the /land/ subfolder.

在根文件夹中的.htaccess文件中使用广泛推荐的mod_rewrite规则(低于code)从 codeigniter维基,这一套规则非常适用于根codeigniter应用程序(应用程序1)。这些规则存在于Web根文件夹中。

The .htaccess file in the root folder uses the widely recommended mod_rewrite rules (code below) from the Codeigniter wiki, and this set of rules works well for the root Codeigniter application (application 1). These rules reside in web root folder.

<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 /陆/的.htaccess 执行mod_rewrite规则。

The above set of rules has no problem removing index.php from the urls in the root Codeigniter application. But this set of rules does not seem to allow the mod_rewrite rules in public_html/land/.htaccess to execute.

当我删除的public_html /的.htaccess mod_rewrite的规则,那么在的public_html /陆/ .htaccess中的mod_rewrite规则开始被评估。

When I remove the mod_rewrite rules in public_html/.htaccess, then the mod_rewrite rules in public_html/land/.htaccess start being evaluated.

有没有办法来改变的public_html /的.htaccess 来处理URL打算访问 /土地的特殊情况下,mod_rewrite规则/ 子文件夹?

Is there a way to change the mod_rewrite rules in public_html/.htaccess to handle the special case of a url intended to access the /land/ subfolder?

我认为最好的解决办法可能是改变的public_html /的.htaccess mod_rewrite的规则,允许在的public_html /陆/ mod_rewrite规则。 htaccess的当子文件夹中的URL地址执行。我愿意接受任何建议。

I think the best solution might be to change the mod_rewrite rules in public_html/.htaccess to allow the mod_rewrite rules in public_html/land/.htaccess to execute when the subfolder is addressed in the url. I am open to any suggestions.

pre-先发制人回答这个问题:你为什么不只是使用一个子? 1.节省金钱上的SSL证书。 2)非介绍技术用户有时会混淆子域营销的基础域名。

Pre-emptive answer to the question "why don't you just use a subdomain?" 1. Saving money on the SSL certificate. 2) Non-techical users are sometimes confused by subdomains for marketing the base domain name.

pre先发制人回答你为什么不结合codeigniter应用程序使用的框架相同的文件?复制该框架文件是一种简单的方法来保持版本库中分离。

Pre-emptive answer to "why don't you combine the Codeigniter applications to use the same files in the framework?" Duplicating the framework files is an easy way to keep the versioning repositories separated.

推荐答案

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

Add a rule at the top to just go to the land subfolder if it's part of the request string. That way, the rules in /land/.htaccess will be executed instead of the subsequent rules in /.htaccess. So put this at the top:

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

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

This will check if the request begins with 'land' and redirect it to the subdirectory, where .htaccess rules corresponding to that subdirectory will be applied instead.

究其原因,现有的规则检查文件和文件夹,而不是做重写,如果该请求符合其中之一是因为无论如下请求土地可能不是一个真正的文件,因此重写规则火灾。

The reason the existing rule checking for files and folders and not doing the rewrite if the request corresponds to one of them is because whatever follows 'land' in the request is probably not a real file, and so the rewrite rule fires.

这篇关于mod_rewrite的从codeigniter在子目录中删除的index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆