【问题标题】:laravel 5.3 first page not showinglaravel 5.3首页没有显示
【发布时间】:2017-01-09 16:11:55
【问题描述】:

我已经在我的系统中安装了 apache2 和 laravel 5.3。我已经将端口 8081 分配给了

/var/www/html/laravel 

文件夹。现在我正在尝试执行

http://localhost:8081/

所以它向我展示了 laravel 的所有文件夹,而不是执行 laravel 的默认页面。那么正确吗?

是否需要为此在 configuration.php 文件中做一些更改?

【问题讨论】:

  • 你需要把它指向/var/www/html/laravel/public
  • 感谢回复。让我试试
  • 好吧,好像它的工作。它向我显示了第一页,例如“马上回来”。
  • 是那个错误页面而不是欢迎页面吗?
  • 可能是维护页面或错误页面。检查您的日志(在 storage/logs/ 中找到,以及您的配置。

标签: php apache laravel-5.3


【解决方案1】:

问题可能与“.htaccess”文件有关。请在 public 文件夹中创建一个 .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>

这对我有用。

【讨论】:

    【解决方案2】:
    <?php
    
    namespace App\Providers;
    
    use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
    use Illuminate\Support\Facades\Route;
    
    class RouteServiceProvider extends ServiceProvider
    {
        /**
         * This namespace is applied to your controller routes.
         *
         * In addition, it is set as the URL generator's root namespace.
         *
         * @var string
         */
        protected $namespace = 'App\Http\Controllers';
    
        /**
         * The path to the "home" route for your application.
         *
         * @var string
         */
        public const HOME = '/'; //************** Make change in this line to default redirection in laravel 7 or in any version*****************strong text**
    
        /**
         * Define your route model bindings, pattern filters, etc.
         *
         * @return void
         */
        public function boot()
        {
            //
    
            parent::boot();
        }
    
        /**
         * Define the routes for the application.
         *
         * @return void
         */
        public function map()
        {
            $this->mapApiRoutes();
    
            $this->mapWebRoutes();
    
            //
        }
    
        /**
         * Define the "web" routes for the application.
         *
         * These routes all receive session state, CSRF protection, etc.
         *
         * @return void
         */
        protected function mapWebRoutes()
        {
            Route::middleware('web')
                 ->namespace($this->namespace)
                 ->group(base_path('routes/web.php'));
        }
    
        /**
         * Define the "api" routes for the application.
         *
         * These routes are typically stateless.
         *
         * @return void
         */
        protected function mapApiRoutes()
        {
            Route::prefix('api')
                 ->middleware('api')
                 ->namespace($this->namespace)
                 ->group(base_path('routes/api.php'));
        }
    }
    

    【讨论】:

    • 您的格式有问题。你应该修复它。并且请在代码前添加一个小总结,而不是只使用内联 cmets。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    • 1970-01-01
    • 2017-09-02
    • 1970-01-01
    • 2017-04-11
    • 2017-12-08
    • 2017-06-06
    相关资源
    最近更新 更多