【问题标题】:htaccess file is not working properly in Laravel on linuxhtaccess 文件在 Linux 上的 Laravel 中无法正常工作
【发布时间】:2019-02-10 10:16:26
【问题描述】:

我正在做一个 Laravel 项目。我正在从 URL 中删除“/public”,但它仅适用于 welcome 页面,其他页面如 /login,/register 无法正常工作。它显示一个错误。

在此服务器上找不到请求的 URL /GME/login。

Apache/2.4.18 (Ubuntu) 服务器在 localhost 端口 80

但是当我在 URL 中使用 public/index.php 时,它可以正常工作。

http://localhost/GME/public/index.php/login

这是我的root.htaccess文件代码。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public/
RewriteRule ^(.*)$ public/$1 [L] #relative substitution
RewriteRule ^ index.php

这是我的/public/.htaccess 文件代码。

<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]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

注意:我使用的是 linux 基本操作系统 loki 版本

【问题讨论】:

  • 你能分享你的文件夹结构吗?
  • 就像laravel项目文件夹结构。
  • 你在哪里设置了DOCUMENT_ROOT?是public 文件夹吗?还是 laravel 项目的根?您的文档根目录应该是 public 文件夹。
  • @SakibulAlam 我正在更新我的问题,请查看目录结构

标签: php laravel .htaccess


【解决方案1】:

我觉得你需要把这个添加到GME目录.htaccess

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

【讨论】:

  • root目录.htaccesspublic/.htaccess?
猜你喜欢
  • 2013-06-07
  • 2016-04-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-22
  • 1970-01-01
  • 2019-08-04
  • 1970-01-01
  • 2021-10-06
相关资源
最近更新 更多