我在共享主机上设置了一个Laravel项目,其中文档根不能设置为Laravel的“公共”文件夹。为了解决这个问题,我使用以下.htaccess文件:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^habbo.gallery$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.habbo.gallery$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
这个很好用。我现在可以通过"https://domain.tld“访问我的项目了。然而,该项目仍然可以通过"https://domain.tld/public/“访问,这正是我想要防止的。我还没有找到这个问题的答案,所以我想知道这是否有可能仅仅使用.htaccess。
发布于 2019-08-05 17:26:04
从公用文件夹复制两个文件并将其粘贴到根文件夹。两个文件是:index.php
和.htaccess
然后在粘贴在根文件夹上的编辑器上打开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__.'/../vendor/autoload.php'; Replace this by following code
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__.'/../bootstrap/app.php'; Replace this by following code
$app = require_once __DIR__.'/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| 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);
https://stackoverflow.com/questions/57362030
复制相似问题