1.我理解您为什么要尝试更改 .htaccess 但这可以更简单地解决。将 .htaccess 文件恢复为 Laravel 标准
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
2。将所有文件夹和文件从 public 中移开,并确保它们位于 HTML 文件夹后面。
3.将所有公用文件夹和文件从公用文件夹移到 html 文件夹中
4.通过更改 server.php 文件告诉 laravel 查看你的 html 文件夹而不是公共文件夹
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell <taylorotwell@gmail.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/html'.$uri)) {
return false;
}
require_once __DIR__.'/html/index.php';
我发现这个解决方案比你乱用 htaccess 简单得多。您还要确保不能从 url 访问所有 Laravel 核心文件。
您遇到的其他问题(内部页面)
这可能是因为你的 apache 不允许用 Laravel htaccess 覆盖
转到服务器的命令行并访问 apache2.conf 文件
cd /etc/apache2
用 nano 打开 apache2.conf 文件
sudo nano apache2.conf
现在找到以下
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
改成
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
写出更改并退出 nano。
重启apache
sudo service apache2 restart
它现在应该可以工作了 :)