dongzhenyin2001 2016-09-20 15:09
浏览 73

从URL Laravel 5.2中删除index.php

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

  • 写回答

2条回答 默认 最新

  • dqhdz04240 2016-09-20 15:15
    关注

    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>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料