【问题标题】:Laravel Project on Pleask except homepage other routes are not workingPleask 上的 Laravel 项目除了主页其他路线都不起作用
【发布时间】:2018-04-14 14:07:55
【问题描述】:

我在 httpdocs 文件夹中的 Plesk 服务器上上传了我的 Laravel 项目文件并更改了必要的权限。现在我的主页工作正常,但其他路由显示 404 服务器错误(见截图 [http://prntscr.com/h54nra][1]

为了检查不同论坛和 stackoverflow 中的少数解决方案,我还尝试在我的 .htaccess 文件中进行更改,但仍无法解决。 目前我正在使用以下代码或 .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}]

如果您找到任何解决方案,请告诉我

【问题讨论】:

  • 你是如何把你的代码放到服务器上的?所以现在你的应用应该通过public:http://appurl.com/public访问它?
  • 我的 index.php 文件位于根目录中,因此无需添加 /public,应用程序在显示主页的根目录中工作:appurl.com。但进一步显示 404 的路由器说:appurl.com/about 不工作
  • 你的服务器使用的是 apache 吗?还是用 nginx 代替?
  • 服务器使用 Microsoft-IIS/8.5
  • 所以你在Microsoft-IIS/8.5 下运行phpphp 模块对吗?无论如何.htaccess 文件只适用于apache。它不适用于IISnginx。你的问题是url重写。很抱歉帮不上忙,因为我从来没有尝试在 IIS 下运行 Laravel 应用程序。我曾经在 Windows 中部署我的 Laravel 应用程序,但我安装了 apache 来运行它。

标签: php laravel .htaccess laravel-5 server


【解决方案1】:

由于您使用的是 IIS,因此 .htaccess 不会参与重定向以打开除主页面之外的任何子页面。相反,应该在域的 web.config 文件中指定重定向,例如:

<configuration>
<system.webServer>
    <defaultDocument>
        <files>
            <clear />
            <add value="index.php" />
            <add value="default.aspx" />
            <add value="Default.htm" />
            <add value="Default.asp" />
            <add value="index.htm" />
            <add value="index.html" />
        </files>
    </defaultDocument>
    <rewrite>
        <rules>
            <rule name="Imported Rule 1" stopProcessing="true">
                <match url="^(.*)/$" ignoreCase="false" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                </conditions>
                <action type="Redirect" redirectType="Permanent" url="/{R:1}" />
            </rule>
            <rule name="Imported Rule 2" stopProcessing="true">
                <match url="^" ignoreCase="false" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                </conditions>
                <action type="Rewrite" url="index.php" />
            </rule>
        </rules>
    </rewrite>
    <httpErrors errorMode="Detailed" />
</system.webServer>

此文件应放置在域的 httpdocs 或 httpdocs/public 文件夹中,具体取决于项目配置。 以下教程可能会提供有关在 IIS 中设置 Laravel 的一些其他详细信息:herehere

【讨论】:

  • 我用这段代码添加了这个文件 web.config,现在我收到 500 错误(截图:prntscr.com/h58s02
  • 我添加了 web.config 文件,主页正在显示,但对于其他页面,我收到错误消息“在此服务器上找不到请求的文档。”。
  • 终于可以了,我在 web.config 文件中添加了您提供的源代码jimfrenette.com/2016/09/laravel-iis-windows-install 并且它现在可以正常工作,我的主页 (app.com) 和其他页面 (app.com/registration等..)现在工作正常。感谢您的帮助
猜你喜欢
  • 1970-01-01
  • 2020-04-28
  • 2017-03-07
  • 2019-11-03
  • 2014-12-18
  • 2015-12-13
  • 1970-01-01
  • 2017-03-01
  • 2017-10-02
相关资源
最近更新 更多