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

时间:2018-03-06 03:55:02

标签: laravel laravel-5.4 plesk

这是我得到的,我尝试使用以下代码将.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"
    }

尚未成功。请帮助我无法入睡

1 个答案:

答案 0 :(得分:0)

好吧我解决了自己的问题

  1. 我通过更改文件夹结构以及匹配服务器和laravel支持的php版本来遵循其他建议,所以在我的情况下我的服务器在php 5.4上运行,我使用的是Laravel 5.4所以我降级了它与4.2。
  2. Plesk for Windows使用IIS HTTP服务器(http://www.iis.net/)来托管和管理网站。所以我在我的&#34; web.config&#34; 文件中配置了(如果它不可用,请在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>