从URL,Laravel 5.2中删除index.php [英] Remove index.php from URL, Laravel 5.2

查看:101
本文介绍了从URL,Laravel 5.2中删除index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了很多例子,并尝试了许多解决方案,但均未成功! 我试图用apache将我的项目放到Ubuntu服务器上.

一切正常:

"/MYEXAMPLE/public/index.php/dashboard" 

但我想要

:

"/MYEXAMPLE/public/dashboard"

有问题!

在此服务器上找不到请求的URL/MYEXAMPLE/public/dashboard."

我的 apache服务器具有de_mod_rewrite.

我的项目文件夹为:

     - MYEXAMPLE
     --------- server.php
     --------- public
     ----------------.htaccess.php 
     ----------------.index.php 
     ---------------- views

我的.htaccess.php:

<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}]

INDEX.PHP:

<?php //


require __DIR__ . '/../bootstrap/autoload.php';


$app = require_once __DIR__ . '/../bootstrap/app.php';


$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
        $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

我不想从公用文件夹中删除我的视图!当我使用wamp服务器时,一切正常,我不需要在URL上使用index.php.现在,我正在尝试使用Ubuntu服务器,但是URL无法正常工作,因为我需要index.php

其他示例:如果我访问

/MYEXAMPLE/public/

OR

/MYEXAMPLE/public/index.php

根据需要转到主页.当我尝试切换到其他页面时,问题出在他身上!

有人建议解决问题吗?为什么使用wamp可以正常运行,当我尝试使用Ubuntu服务器时,需要URL上的index.php吗?

预先感谢

解决方案

您需要

此外,您可以使用为Laravel运行Apache虚拟主机配置:

<VirtualHost some.app:80>
    DocumentRoot "/path_to_laravel_project/public"
    ServerName some.app
    ServerAlias some.app

    <Directory "/path_to_laravel_project/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

I saw a lot of examples and tried a lot of solutions without success! I am trying to put my project to Ubuntu server with apache.

everything its ok when I do :

"/MYEXAMPLE/public/index.php/dashboard" 

But I want:

"/MYEXAMPLE/public/dashboard"

And there is the problem!

"The requested URL /MYEXAMPLE/public/dashboard was not found on this server."

My apache server has de mod_rewrite.

My project folders are:

     - MYEXAMPLE
     --------- server.php
     --------- public
     ----------------.htaccess.php 
     ----------------.index.php 
     ---------------- views

My .htaccess.php:

<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}]

INDEX.PHP:

<?php //


require __DIR__ . '/../bootstrap/autoload.php';


$app = require_once __DIR__ . '/../bootstrap/app.php';


$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
        $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

I do not want to remove my views from public folder! When I use wamp server, everything ok, I do not need to use the index.php at the URL. Now I am trying to use the Ubuntu server, but the URL's are not working because I need index.php

Other example: If I access

/MYEXAMPLE/public/

OR

/MYEXAMPLE/public/index.php

It goes to homepage as I want. The problem his when I am trying to change to other page!

Any sugestions to solve the problem? Why everything is ok running with wamp and when I try to use the Ubuntu server, I need the index.php at the URL?

Thanks in advance

解决方案

You need to point web server to public directory and use normal URLs like /dashboard instead of /public/index.php/dashboard.

DocumentRoot "/path_to_laravel_project/public"
<Directory "/path_to_laravel_project/public">

Also, you can use this working Apache virtual host configuration for Laravel:

<VirtualHost some.app:80>
    DocumentRoot "/path_to_laravel_project/public"
    ServerName some.app
    ServerAlias some.app

    <Directory "/path_to_laravel_project/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

这篇关于从URL,Laravel 5.2中删除index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆