基本上,我需要删除的index.php
或公共/ index.php文件
从laravel在生成的URL通常路径是本地主机/公/ index.php文件/ someWordForRoute
,它应该是这样的本地主机/ someWordForRoute
Basically I need to remove index.php
or public/index.php
from the the generated URL in laravel, commonly path is localhost/public/index.php/someWordForRoute
, It should be something like localhost/someWordForRoute
htacces
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php[L]
应用/配置/ app.php
'url' => 'http://localhost',
我怎样才能改变这种状况?
how can I change that?
创建一个的.htaccess
提交您Laravel根目录下,如果它不存在了。 (正常情况下它是根据你的的public_html
文件夹)
Create a .htaccess
file your Laravel root directory if it does not exists already. (Normally it is under your public_html
folder)
和添加以下code到它:
And add the following code to it:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
现在,你可以通过 http://example.com
其实我preFER这种方法,因为上述的方法是不那么好在生产环境中使用。
Actually i prefer this method because the above method is not so good to use in production environment.
所以,现在让创建一个新的文件夹laravelfiles在你的根目录下,并将所有文件和文件夹除公共目录laravelfiles。
So now lets make a new folder laravelfiles in your root directory and move all the files and folder except public directory to laravelfiles.
和移动公共目录的一切,根文件夹。现在,你的根目录将是这个样子:
And move everything of public directory to root folder. Now your root directory will look something like this:
现在我们要改变在的路径laravelfiles /引导/ paths.php
文件和的index.php
。
Now we have to change the paths in laravelfiles/bootstrap/paths.php
file and index.php
.
查找 laravelfiles这些行/引导/ paths.php
'app' => __DIR__.'/../app',
'public' => __DIR__.'/../public',
更改这些两行:
Change these two lines to:
'app' => __DIR__.'/../app',
'public' => __DIR__.'/../../',
查找这些行的index.php
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';
和更改为:
require __DIR__.'/laravelfiles/bootstrap/autoload.php';
$app = require_once __DIR__.'/laravelfiles/bootstrap/start.php';
来源:如何删除/公/从Laravel 网址