【问题标题】:Run multiple subfolder websites in one separate folder在一个单独的文件夹中运行多个子文件夹网站
【发布时间】:2016-04-11 02:35:04
【问题描述】:

我有一个主要网站 (example.com)。我在那里使用 CodeIgniter 框架。

我还将使用一些不同的子文件夹,例如 example.com/sub1example.com/sub2。我在这里使用 Laravel 框架,这些框架与 example.com 完全不同,并存储在不同的文件夹中。当我开始第一个子域时,我在 Apache2 配置中使用了Alias,它运行良好。但是我现在需要使用第二个子文件夹。我在 Apache 配置中添加了第二个 Alias sub2,它指向与 sub1 相同的目录。然后我将 .htaccess 更改为:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond $1 !^(img|js|css)
    RewriteCond %{REQUEST_URI} (/evim)
    RewriteRule ^ /evim/index.php [L]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond $1 !^(img|js|css)
    RewriteCond %{REQUEST_URI} (/crm2)
    RewriteRule ^ /crm2/index.php [L]
</IfModule>

现在它工作正常。 example.com/sub1 和 example.com/sub2 都运行相同的应用程序。但是在 Laravel 中,很难找到当前正在运行的子域。在路由中,应用程序看不到子文件夹名称。例如,如果我使用users/login 路由,那么它匹配example.com/sub1/users/loginexample.com/sub2/users/login。我需要用子文件夹名称定义路由。

我正在寻找 htaccess 或 Laravel 中的解决方案来修复路由。

【问题讨论】:

  • 在codeigniter中我发现最好的方法是创建子目录。称为 Admin 或任何您想要的后端名称,带有自己的 index.php 和应用程序文件夹。另一个名为目录的文件夹主要 index.php 将使用目录作为应用程序文件夹。如果您想为这两个目录制作库,请将其放在系统 lib 文件夹中。它的工作原理我正在做类似的工作,只是在管理安全方面完成了大部分工作而且我发现 htacess 越少越好。
  • example.com 使用 CodeIgniter,但子文件夹应用程序使用 Laravel。我想让它们在文件系统中完全分开。
  • 我会尽量坚持一帧工作

标签: php .htaccess codeigniter mod-rewrite laravel


【解决方案1】:

我会使用这种模式(作为子域),它也许可以避免问题。

http://site1.foo.com http://site2.foo.com

在 CodeIgniter Route.php 中,您可以执行以下操作:

$server_link = explode(".", $_SERVER["HTTP_HOST"]);

if ( $server_link[0] == "site1" )
{
   $route['default_controller'] = 'home';
   // Some Other Routes
}

我认为你可以对 Laravel 路由做同样的事情。

【讨论】:

  • 是的,子域是一个非常简单的解决方案,但是我不能使用子域。
【解决方案2】:

我使用Request::server('HTTP_HOST') 来获取加载了哪个站点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-09
    • 2022-11-17
    • 2023-03-04
    • 2015-05-23
    相关资源
    最近更新 更多