Htaccess重写为父目录中的PHP文件 [英] Htaccess Rewrite to PHP File in Parent Directory

查看:69
本文介绍了Htaccess重写为父目录中的PHP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用具有许多子应用程序的自定义框架.我想为每个应用程序文件夹分配一个域,但是遇到了问题.

I use a custom framework which has many sub applications. I want to assign a domain to each application folder but ran into an issue.

Apache vhosts配置

<VirtualHost *:80>
        ServerName app1.com
        DocumentRoot /var/www/framework/public/app1
</VirtualHost>

<VirtualHost *:80>
        ServerName app2.com
        DocumentRoot /var/www/framework/public/app2
</VirtualHost>

/var/www/framework/.htaccess

DirectorySlash Off

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)/?$ index.php?_ROUTE=$1 [QSA]

/var/www/framework/index.php

<?php
exit('WORKED!');

//Route request
//...

一切正常,但实际上我想使用索引文件"/"时,它尝试使用文档根目录中的index.php文件,例如"/var/www/framework/public/app1/index.php" var/www/framework/index.php".

Everything's works fine except that it tries to use the index.php file in the document root such as "/var/www/framework/public/app1/index.php" when actually I want to use the index file "/var/www/framework/index.php".

那么,如何在.htaccess位置上方或相对位置的两个目录中使用index.php文件?

So how would I get it to use the index.php file two directories above or relative to the .htaccess location?

推荐答案

您要做的本质上是一个多站点应用程序.

What you're doing is essentially a multi-site application.

您应将文档根目录设置为包含主index.php文件的文件夹.然后,应该通过检查 $_SERVER超全局性,例如:

You should set the document root to the folder that contains the main index.php file. Then that should route the request to the required app by checking the HTTP host property in the $_SERVER superglobal, like for example:

switch ($_SERVER['HTTP_HOST']) {
    case 'app1.com':
        include 'app1/index.php';
        // Do stuff
        break;

    case 'app2.com':
        include 'app2/index.php';
        // Do stuff
        break;
}

这篇关于Htaccess重写为父目录中的PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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