如何使我的路由可访问而不使用公共在共享主机使用laravel,我试图使用这个。htaccess,但它不工作
RewriteEngine上rewriterrule ^(.*)$ public/$1 [L]我目前使用hostinger,我的文件夹结构是
→public_html→laravel文件
输入图片描述
我的索引在公共文件夹
我尝试了这个。htaccess代码,但不工作RewriteEngine上rewriterrule ^(.*)$ public/$1 [L]
我的索引在公共文件夹
将公共文件夹下的index.php
和.htaccess
文件移动到父文件夹。
不要忘记修复index.php
文件中的路径。这样的:
// require __DIR__ . '/../vendor/autoload.php'; to...
require __DIR__ . '/vendor/autoload.php';
您的项目将在public_html中触发.
这种情况下的最佳实践是通过这样创建htaccess:如何将所有请求重定向到laravel 5中的public/folder
但是我们仍然有一个"不太推荐"。处理托管提供商有限功能的技巧:
- 移动项目文件中的所有文件(除了"public"目录),并创建新的"private"文件夹中。在这一步中,"私有"one_answers";public">
- private
- app
- bootstrap
- config
- database
- ...
- public
- index.php
- your_assets_or_anything
- ...
- 移动所有"公共"目录内容到根项目。在这一步中,目录结构将像这样:
- private
- app
- bootstrap
- config
- database
- ...
- index.php
- your_assets_or_anything
- ...
- 最后一次打开"index.php"当前在根目录中的文件,将所有
/../
替换为/private/
。例子:
<?php
use IlluminateContractsHttpKernel;
use IlluminateHttpRequest;
define('LARAVEL_START', microtime(true));
// ...
if (file_exists($maintenance = __DIR__.'/private/storage/framework/maintenance.php')) {
require $maintenance;
}
// ...
require __DIR__.'/private/vendor/autoload.php';
// ...
$app = require_once __DIR__.'/private/bootstrap/app.php';
$kernel = $app->make(Kernel::class);
$response = $kernel->handle(
$request = Request::capture()
)->send();
$kernel->terminate($request, $response);
请记住,这个技巧有一个安全问题。你需要保护所有私有文件不被公众访问。