.htaccess 从URL中没有公共路径的公共文件夹在子域的子文件夹上运行网站

4smxwvx5  于 2023-05-07  发布在  其他
关注(0)|答案(1)|浏览(132)

通常,我创建一个子域,并将文档根目录更改为公共文件夹,如public_html/subdomain/public,因此当我访问https://subdomain.example.com时,它从公共文件夹运行,而无需在URL中添加公共路径。
现在,我在子域public_html/subdomain/subfolder的子文件夹中有一个Laravel项目,我想从公共文件夹运行该项目以避免此https://subdomain.example.com/subfolder/public
该网站托管在VPS服务器上,因此我可以访问所有内容。
如何使子域上的子文件夹上的项目从公共文件夹运行,而不将/public添加到URL?
我试了一下.htaccess

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]

但它会将/public附加到URL。

xtfmy6hx

xtfmy6hx1#

移动public_html/subdomain/subfolder中除public文件夹外的所有文件,并在public_html/subdomain/main新建一个文件夹,即
主要的
然后将所有文件移动到主文件夹,然后将所有文件和文件夹从public移动到public_html/subdomain/subfolder并编辑您的index.php,它将看起来像这样

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/

require __DIR__.'/../main/vendor/autoload.php';  // previous line require __DIR__.'/../vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../main/bootstrap/app.php'; // add main here also

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

你只需要编辑2行代码就可以了requireDIR**.'/../vendor/autoload.php';需要DIR.'/../main/vendor/autoload.php';第二行来自$app = require_onceDIR.'/../bootstrap/app.php';to$app = require_onceDIR.'/../main/bootstrap/app.php';**您的文件夹结构应该类似于此public_html/subdomain

├── subfolder
│   ├── index.php
│   ├── .htaccess
├── main
│   ├── app
│   ├── bootstrap
│   ├── config
│   ├── database
│   ├── resources
│   ├── routes
│   ├── storage
│   ├── tests
│   ├── vendor
│   ├── .env
│   ├── artisan
│   ├── composer.json

相关问题