【问题标题】:apache setup .htaccess rewriteRule with laravelapache设置.htaccess rewriteRule与laravel
【发布时间】:2020-07-17 06:45:06
【问题描述】:

我正在设置 (laravelproj/public/.htaccess)

我在 2 个不同服务器上工作的示例如下:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>
    RewriteEngine On

    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://takaful.hsn93.com/$1 [R,L]

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

</IfModule>

现在我正在cent OS apache (httpd) 上尝试它(如果重要的话) 当我输入链接 (http://example.com/)

我没有任何其他问题,除了这个链接^没有参数^

禁止

您无权访问此服务器上的 /。

为了让它工作,我要评论这一行(检查请求的目录是否为非目录的条件:

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

这是有道理的,因为 / 当然是一个目录..

但是为什么这个 .htaccess 配置在所有其他机器上都有效? 这台机器上有什么不同使得这种情况从 apache 返回了一个禁止项

【问题讨论】:

  • Laravel ships with an .htaccess - 除非您需要特殊的东西,否则不要修改这些部分。 403 可能与 .htaccess 无关,只是一个 Apache 配置问题。尝试删除您的 .htaccess 以确认。 Theremany 问题/答案 here 关于修复 403 的问题。
  • @Don'tPanic laravel 工作完美期待 url (/) 它没有被路由到 index.php .. 这就是为什么我不得不改变它.. 我发布了我相信的虚拟主机配置是的.. 我会再看看你发布的内容,但早些时候我找不到与我类似的问题
  • @Don'tPanic 谢谢,我现在把原来的htaccess文件在发现(index.php)需要在httpd.conf文件中建立索引

标签: laravel apache .htaccess


【解决方案1】:

我发现问题在于 httpd.conf

不索引 (index.php) 文件只是 (index.html)

所以我修改了它

<IfModule dir_module>
    DirectoryIndex index.html
    DirectoryIndex index.php
</IfModule>

【讨论】:

  • 他们应该在一行 - DirectoryIndex index.html index.php。如有疑问,check the docs!
猜你喜欢
  • 1970-01-01
  • 2017-04-21
  • 2016-04-06
  • 2012-12-29
  • 2016-04-06
  • 2023-03-28
  • 1970-01-01
  • 2014-07-04
  • 2012-12-30
相关资源
最近更新 更多