Remove public from url laravel

http://laravel.com/

http://kejyun.github.io/Laravel-4-Docum ... roduction/
回覆文章
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

Remove public from url laravel

文章 yehlu »

http://tutsnare.com/remove-public-from-url-laravel/

Remove public from url laravel 5 and Lower versions:-

Default laravel access url will be http://example.com/public/. so you need to remove “public” from url to get clean urls in laravel 5. let’s check how to remove public from url in laravel.

There is two solution to remove public from url laravel :-

1. Using .htaccess :-
Add following code in your .htaccess (if not exist create a .htaccess on laravel root directory)



RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
2. using content moving :-

It’s a better and simple method to remove public from url laravel below are the steps to do this:-

1. Create a folder on root with named local(you can give any name).
2. Move all files except public folder in the local folder.
3. Move all the files of public to root directory and remove blank public folder.
so directory structure will be :-
Root
a. local – which have all root files except public folder
b. all files of public folder.


laravel(root)
-- local
-- app
-- boostrap
-- .gitattributes
-- composer.json
-- server.php
-- and so on ----
-- packages
-- .htaccess
-- favicon.ico
-- index.php
-- robots.txt
4. Now time to change some paths:-

Note:- Skip step (a) to remove public from url in laravel 5.
In laravel 5 directory structure has been changed also you will not found paths.php in bootstrap so this step need to be skip for laravel 5.
a. open local/bootstrap/paths.php and find below code


'public' => __DIR__.'/../public',
change with below code


'public' => __DIR__.'/../../',
b. open index.php (on root) and find below code


require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';
change with below code


require __DIR__.'/local/bootstrap/autoload.php';
$app = require_once __DIR__.'/local/bootstrap/start.php';
Now you have all set you can access url http://example.com/ if still problem try with clear cache of browser.
回覆文章

回到「laravel」