【问题标题】:Removing index.php from URL laravel 5.4 when virtual hosts points to public folder当虚拟主机指向公用文件夹时,从 URL laravel 5.4 中删除 index.php
【发布时间】:2017-10-29 04:34:02
【问题描述】:

这里和其他地方有无数的帖子请求帮助从实时服务器上的全新 laravel 安装中取出 public/ 和 index.php。事实上,我有点不好意思问这个问题。但是,鉴于给猫剥皮的方法不止一种,我觉得许多不同的解决方案有时会相互冲突并导致更多的头痛。

我通过将虚拟主机 domainname.com.conf 指向 public 文件夹,从最近启动的 laravel 站点中取出了 url 中的“public”。

然而,这导致需要在所有请求中将 index.php 放在域之后,否则页面将无法正常工作。

当我手动将 index.php 放入 url 时,某些图像无法加载,因为它们没有硬编码。

此外,如果我将虚拟主机地址直接指向 public/index.php,该站点可以运行,但大约 10 分钟后它停止运行,并且站点上的任何内容都不会加载、css、js 图像。这一切都停止了。我认为这与 laravel 视图缓存有关,但清除它们不会改变任何事情。

在这一点上,我不知所措。我已经为此工作了 +8 小时,现在已经非常绝望了。

这是我公开的 htaccess 文件夹(不需要 laravel root 中的 htaccess?)

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

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

这与我成功用于其他域和 laravel 实时站点的设置相同。出于某种原因,index.php 根本不会使用任何人的解决方案。

有什么帮助吗?我是不是盯着同一个 htaccess/virtualhost 文件看太久了?

【问题讨论】:

    标签: laravel .htaccess ubuntu apache2


    【解决方案1】:

    好像您没有正确设置 DirectoryIndex。

    检查您的配置,在我的情况下,我在 dir.conf 文件中找到了它:

    文件:/etc/apache2/mods-available/dir.conf

    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

    【讨论】:

    • 我的 dir.conf 看起来和你的一模一样。
    • .conf 文件是否存在于 /etc/apache2/mods-enabled/ 目录中?
    • 是的,它也在那里。
    猜你喜欢
    • 2013-08-14
    • 2019-03-30
    • 1970-01-01
    • 2012-09-22
    • 2012-11-16
    • 2018-07-05
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    相关资源
    最近更新 更多