【问题标题】:Laravel project is calling the wrong pathsLaravel 项目调用了错误的路径
【发布时间】:2021-07-10 13:45:40
【问题描述】:

我是 Laravel 的新手,我正在测试我制作的应用程序。在本地它工作正常,但是当我将它推送到服务器时,路由似乎真的很糟糕。通常视图的路径类似于156.0.125.1/app/index,但它一直在寻找 156.0.125.1/index,这会导致在服务器上找不到 URL 的错误

我怀疑它是 .htaccess 文件,但我不太确定要在那里更改什么,因为我不熟悉它。

服务器上的站点似乎也无法读取 css 和 js

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

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

# Disable Directory listing
Options -Indexes

# block files which needs to be hidden, specify .example extension of the file
<Files ~ "\.(env|json|config.js|md|gitignore|gitattributes|lock)$">
    Order allow,deny
    Deny from all
</Files>

【问题讨论】:

  • 欢迎,你能提供.htaccess的内容吗?
  • 对不起,忘了补充,现在有

标签: javascript php css laravel laravel-8


【解决方案1】:

将此文件 app/public/index.php 移动到您的服务器文档根目录

并进行以下更改 改变 ''' 需要 DIR.'/../vendor/autoload.php ''' 到 ''' 需要 DIR.'/app/vendor/autoload.php ''' 改变 ''' require_once DIR.'/../bootstrap/app.php ''' 到 ''' require_once DIR.'/app/bootstrap/app.php ''' 在 app/server.php 中进行以下更改

改变 ''' require_once DIR.'/public/index.php ''' 到 ''' require_once DIR.'/../index.php '''

【讨论】:

  • 好的,你能告诉我这会做什么吗?
  • 我的根目录下已经有一个 index.php,但它和公共文件夹中的那个不一样
  • @Juststartedcoding public/index.php 文件是你的 laravel 应用程序的入口点,它应该在你的服务器文档根目录。更改只是为了修改调用 public/index.php 文件的脚本的路径,以及从文件中调用的脚本的路径,因为它已被移动。启用调试模式并检查 500 错误的原因
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-09
  • 2011-12-27
  • 2022-01-02
  • 2016-04-28
  • 1970-01-01
  • 2017-01-06
相关资源
最近更新 更多