如何在本地和共享托管服务器的laravel 5.4项目中删除“public / index.php”?

问题描述 投票:0回答:1

这是我得到的,我尝试使用以下代码将.htaccess放在root上:

<IfModule mod_rewrite.c>
   RewriteEngine On 
   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

并在公用文件夹.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>

这是我在localhost:Sorry, the page you are looking for could not be found on localhost上的错误

这是我在共享托管服务器上的错误:Plesk Server Shared Hosting error

"require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.4.*",
        "laravel/tinker": "~1.0",
        "laravelcollective/html": "^5.4.0"
    }

还没有成功。请帮助我无法入睡

laravel laravel-5.4 plesk
1个回答
0
投票

好吧,我解决了自己的问题

  1. 我通过更改文件夹结构以及匹配服务器和laravel支持的php版本来遵循其他人的建议,所以在我的情况下我的服务器在php 5.4上运行,我使用的是Laravel 5.4,因此我将其降级为4.2。
  2. Plesk for Windows使用IIS HTTP服务器(http://www.iis.net/)来托管和管理网站。所以我在我的“web.config”文件中配置(如果它不可用,则在root上创建一个)以使其全部工作 <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> </configuration> 的index.php require __DIR__.'/your_root_folder_name/bootstrap/autoload.php'; $app = require_once __DIR__.'/your_root_folder_name/bootstrap/start.php'; $app->run(); 的.htaccess <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule>
© www.soinside.com 2019 - 2024. All rights reserved.