简体   繁体   English

从URL,Laravel 5.2中删除index.php

[英]Remove index.php from URL, Laravel 5.2

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. 我试图用apache将我的项目放到Ubuntu服务器上。

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." “在此服务器上找不到请求的URL / MYEXAMPLE / public / dashboard。”

My apache server has de mod_rewrite. 我的Apache服务器具有de mod_rewrite。

My project folders are: 我的项目文件夹是:

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

My .htaccess.php: 我的.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: 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. 使用wamp服务器时,一切正常,我不需要在URL上使用index.php。 Now I am trying to use the Ubuntu server, but the URL's are not working because I need index.php 现在,我正在尝试使用Ubuntu服务器,但是URL无法正常工作,因为我需要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? 为什么使用wamp可以正常运行,当我尝试使用Ubuntu服务器时,URL上需要index.php吗?

Thanks in advance 提前致谢

You need to point web server to public directory and use normal URLs like /dashboard instead of /public/index.php/dashboard . 您需要将Web服务器指向public目录,并使用/dashboard类的常规URL代替/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 : 另外,您可以为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>

there are two solution for this problem. 这个问题有两种解决方案。 1.edit your .htaccess to 1.编辑您的.htaccess

DirectoryIndex index.php

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]

RewriteRule .? %{ENV:BASE}/index.php [L]

2.dont edit your code and only run in cmd 2.不要编辑代码,只能在cmd中运行

 php artisan serve

i offer you second solution for this problem 我为您提供第二个解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM