How to Remove Public URL Laravel. For those who are already familar with laravel, surely knowing that the application laravel opened with url /public if you put on xampp , or others. Not funny is if our application use /public? In this post i will show you How to Remove Public URL Laravel.
Actually, to handle it quite easily. There are several alternative ways that we can use, among other things:
[Image]
Method 1: You have a Server Alone
If you have a server yourself, how to remove /public is very easy. Just go to the httpd.conf then edit the document root folder refers to laravel /public
<VirtualHost *:80>
DocumentRoot "/path/to/laravel/public"
ServerName laravel-no-public.com
ServerAlias www.laravel-no-public.com
</VirtualHost>
Method 2: Change Folder Structure
Let's say you have a folder structure as follows: [Image]
Next, create a new folder with a name protected: [Image]
Then move all files and folders (except public folder) into a protected folder you just created: [Image]
Finally, move the public folder contents to the outside so that the equivalent protected folder earlier. Make sure the .htaccess file also moved. Public folders that you can empty.[Image]
Up here you can access the application without having to add frills / public on the back, but will encounter an error like this:
Warning: require(/Users/uyab/Sites/public_html/public/../bootstrap/autoload.php): failed to open stream: No such file or directory in /Users/uyab/Sites/public_html/public/index.php on line 21
Fatal error: require(): Failed opening required '/Users/uyab/Sites/public_html/public/../bootstrap/autoload.php' (include_path='.:/Applications/MAMP/bin/php/php5.4.10/lib/php') in /Users/uyab/Sites/public_html/public/index.php on line 21
Edit Index.php
require __DIR__.'/protected/bootstrap/autoload.php';
...
$app = require_once __DIR__.'/protected/bootstrap/start.php';
Edit protected/bootrap/bootstrap/paths.php
'public' => __DIR__.'/../..',
Method 3: The Simplest Way
The framework ships with a public/.htaccess file that is used to allow URLs without index.php. If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module.
If the .htaccess file that ships with Laravel does not work with your Apache installation, try this one:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Nginx
On Nginx, the following directive in your site configuration will allow "pretty" URLs:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
Conclusion:
There are several ways to remove / public on laravel. The simplest way is to change
"How to Remove Public URL Laravel"
No comments yet. -