Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 一个站点上的多个Mod_重写-可能吗?(根目录中的Wordpress博客,子目录中的CodeIgniter项目)_Apache_Wordpress_.htaccess_Mod Rewrite_Codeigniter - Fatal编程技术网

Apache 一个站点上的多个Mod_重写-可能吗?(根目录中的Wordpress博客,子目录中的CodeIgniter项目)

Apache 一个站点上的多个Mod_重写-可能吗?(根目录中的Wordpress博客,子目录中的CodeIgniter项目),apache,wordpress,.htaccess,mod-rewrite,codeigniter,Apache,Wordpress,.htaccess,Mod Rewrite,Codeigniter,目前,我正在使用CodeIgniter创建一个项目,该项目包含在我的域的子目录中。对于本例,我们将其称为domain.com/test 我也在这个域上安装了Wordpress,它的所有文件都在根目录中。例如,如果你导航到my domain.com,它就会调出Wordpress博客。我目前已经激活Wordpress mod_rewrite,以便它使用友好的URL 对于那些不熟悉CodeIgniter的人,所有请求都通过项目根文件夹中的index.php路由。因此,在本例中,应该是domain.co

目前,我正在使用CodeIgniter创建一个项目,该项目包含在我的域的子目录中。对于本例,我们将其称为domain.com/test

我也在这个域上安装了Wordpress,它的所有文件都在根目录中。例如,如果你导航到my domain.com,它就会调出Wordpress博客。我目前已经激活Wordpress mod_rewrite,以便它使用友好的URL

对于那些不熟悉CodeIgniter的人,所有请求都通过项目根文件夹中的index.php路由。因此,在本例中,应该是domain.com/text/index.php。向应用程序发送的请求类似于domain.com/test/index.php/somecontroller/method

我想做的是,对于任何指向/test/文件夹或其中某个子目录的传入请求,我希望它适当地重写URL,以便不包括index.php。(根据上面的例子,它最终将成为domain.com/test/somecontroller/method)

对于任何其他请求,即不在/test/目录中的任何请求,我希望它将请求路由到Wordpress

我可以想象,这是一个简单的重写,让它检查请求是针对/test/目录还是其中的子目录,但我不知道如何做。也许每个站点最多只能有一组重写规则

我将为每个应用程序提供推荐的mod_重写规则

Wordpress:(当前使用)


重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
代码点火器:(从其上拔下)


重新启动发动机
重写基/
#删除用户对系统文件夹的访问权限。
#此外,这将允许您创建System.php控制器,
#以前这是不可能的。
#如果已重命名系统文件夹,则可以替换“系统”。
重写COND%{REQUEST_URI}^系统*
重写规则^(.*)$/index.php?/$1[L]
#当应用程序文件夹不在系统文件夹中时
#此代码段阻止用户访问应用程序文件夹
#提交人:Fabdrol
#将“应用程序”重命名为应用程序文件夹名称。
重写cond%{REQUEST_URI}^应用程序*
重写规则^(.*)$/index.php?/$1[L]
#检查用户是否试图访问有效文件,
#例如图像或css文档,如果这不是真的,它会发送
#请求index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L]
#如果我们没有安装mod_rewrite,所有404
#可以发送到index.php,一切正常。
#提交人:ElliotHaughin
ErrorDocument 404/index.php
非常感谢您的任何帮助

谢谢


-Sootah

@我自己和Stormdrain——正如我在上面的评论中所说的(并由Stormdrain进行了阐述),简单地将CodeIgniter.htaccess放在/test/子目录中就成功了

啊,我还应该注意到,我必须修改CodeIgniter.htaccess基线,如下所示: 重写基/

为此: 重写基础/测试/

希望这能帮助其他有相同/类似问题的人


-

显然,我真正需要做的就是将.htaccess添加到/test/子目录,其中包含的规则显然覆盖了父目录规则。但是,我仍然想知道这在一个.htaccess中是否可行。您需要单独的.htaccess文件,因为如果用户进入测试目录,根目录中的.htaccess将看不到,因此其“指令被忽略…”。。。
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>
<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
    #Submitted by: Fabdrol
    #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.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>