【发布时间】:2021-10-17 11:03:47
【问题描述】:
我在 Laravel 项目中遇到以下情况。我将项目上传到 /var/www/html/tup 文件夹中的 Linux 服务器。
我可以使用链接http://www.example.com/tup/public 访问该站点,如图所示 (First Image)
我想直接访问而不在 URL i 中输入 public。 e. http://www.example.com/tup
我尝试在项目的主文件夹中使用 .htaccess 文件:
<IfModule mod_rewrite.c>
# That was ONLY to protect you from 500 errors
# if your server did not have mod_rewrite enabled
RewriteEngine On
# RewriteBase /
# NOT needed unless you're using mod_alias to redirect
RewriteCond %{REQUEST_URI} !/public
RewriteRule ^(.*)$ public/$1 [L]
# Direct all requests to /public folder
</IfModule>
但是当我进入http://www.example.com/tup时,Laravel 会抛出 404 Not Found 错误 (404 error Image)。我必须写 http://www.example.com/tup/index.php 让 Laravel 像 this image 一样重定向我。
好像没有检测到index.php文件
在公用文件夹中我有另一个 .htaccess 文件:
DirectoryIndex index.php index.html
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
我已经修改了 apache2.conf 文件并将所有 AllowOverride 设置为 All 并启用了 mod_rewrite。
我也在apache2.conf中添加了这个配置:
<Directory /var/www/html/tup/public/>
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
如果能提供任何帮助,我将不胜感激。
【问题讨论】:
-
你重启服务器了吗?
sudo systemctl apache2 restart -
是的,我重启了好几次。
-
试试我在答案中写的
标签: php linux laravel apache debian