unable to remove index.php from laravel url ?? in

2019-09-05 08:39发布

问题:

there I just created a new project in laravel 5.2. then I had successfully removed public/index.php from url of my project in windows it works fine. But While I copied the same project in ubuntu inside var/www/html as /var/www/html/myproject. And enabled apache2 rewrite_mode. But it no work without putting index.php in url. It works without public only. http:://localhost/myproject/index.php/cms (it works fine) BUT http:://localhost/myproject/cms(it does not works)??? .Any suggestion???? my code is as

route.php

define( "PREFIX", "cms" );
Route::get(PREFIX . '/login', 'Auth\AuthController@getLogin');

it fine also I already cut all files from public folder to root directory and edit index.php file as

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

By

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

and

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

by

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

.htaccess as

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

回答1:

I ran into this and foud a solution on http://laravel.io.

On Apache 2.4.7 the apache2.conf is set to not allow .htaccess override by setting AllowOverride None:

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

You can change this in apache2.conf, but this is not recommended. Instead do this override in the VirtualHosts file for your site ie. sites-available/yoursite.com.conf. Something like this:

<Directory /var/www/html/yoursite.com/laravelappinstall/public/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Make sure that you have enabled the rewrite module ie. sudo a2enmod rewrite. Restart your web server ie. sudo service apache2 restart.

Source: http://laravel.io/forum/09-15-2015-removing-indexphp-from-url-laravel-5116



回答2:

•Go to mainproject/public>>

a.  .htacess
b.  favicon.ico
c.  index.php
d.  robots.txt
e.  web.config

1.cut these 5 files from public folder,and then paste on the main project folder that’s means out side of public folder… mainproject/files

2.Next after paste ,open index.php ,modify

•require __DIR__.'/…/bootstrap/autoload.php';  to
•require __DIR__.'/bootstrap/autoload.php';

modify

 $app = require_once DIR.'/../bootstrap/app.php'; to
 $app = require_once DIR.'/bootstrap/app.php';