无法从laravel网址中删除index.php?在Ubuntu 14.04中 [英] unable to remove index.php from laravel url ?? in ubuntu 14.04
问题描述
有
我刚刚在laravel 5.2中创建了一个新项目.那么我已经在Windows中从项目的URL中成功删除了public/index.php
,它工作正常.
但是,虽然我在var/www/html中的ubuntu中将同一项目复制为/var/www/html/myproject
.并启用apache2 rewrite_mode.但是,如果不将index.php放在url中,那就没有用.它仅在不公开的情况下有效.
http:://localhost/myproject/index.php/cms
(正常工作)但
http:://localhost/myproject/cms
(它不起作用)???有任何建议吗???
我的代码是
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');
还好 我已经将所有文件从公用文件夹剪切到根目录,并将index.php文件编辑为
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';
通过
require __DIR__.'/bootstrap/autoload.php';
和
$app = require_once __DIR__.'/../bootstrap/app.php';
作者
$app = require_once __DIR__.'/bootstrap/app.php';
.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>
推荐答案
我遇到了这个问题,并在 http://laravel上找到了解决方案.io .
I ran into this and foud a solution on http://laravel.io.
在Apache 2.4.7上,通过设置AllowOverride None:将apache2.conf设置为不允许.htaccess覆盖:
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>
您可以在apache2.conf中进行更改,但是不建议这样做.而是在您网站的VirtualHosts文件中执行此覆盖,即. sites-available/yoursite.com.conf.像这样:
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>
确保已启用重写模块,即. sudo a2enmod重写.重新启动您的Web服务器. sudo服务apache2重新启动.
Make sure that you have enabled the rewrite module ie. sudo a2enmod rewrite. Restart your web server ie. sudo service apache2 restart.
来源: http://laravel. io/forum/09-15-2015-removing-indexphp-from-url-laravel-5116
这篇关于无法从laravel网址中删除index.php?在Ubuntu 14.04中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!