erbaig
Last Updated: April 17, 2019
·
157.5K
· hnordt

Laravel's .htaccess to remove "public" from URL

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Place this file in Laravel's root directory.

Please note that this isn't the recommended way. A safer way is place Laravel's files outside your web server root and make the Laravel's public directory your web server root. Don't forget to update the paths.php file.

9 Responses
Add your response

3795

I tried this and it doesn't work for me - I keep getting a 404 error from Laravel. Any thoughts on how I could troubleshoot?

over 1 year ago ·
6244

I had the same problem as tridnguyen. This method only works if the base laravel folder is the webroot, it wont work if the base laravel folder is a subfolder of the webroot

over 1 year ago ·
7575

Here is where I found the answer. Tested in local and production server:

http://creolab.hr/2013/03/removing-the-public-segment-in-a-laravel-4-app/

over 1 year ago ·
8508

just for the guys using IIS like me, my solution (workaround, I'd say) was to strip index.php from the url by importing the standard .htaccess and then I create a virtual directory, say "employees" pointing to D:\inetpub\wwwroot\lv\employees\public; then navigating thru localhost/employees/controller/method seems to work fine.

over 1 year ago ·
27531

I has try, but it don't, my apache use port 8080.

over 1 year ago ·
28540
32260

@tridnguyen make sure that you have configured htaccess with your web server, Apache, correctly. For rewriting htaccess for Laravel on shared hosting, it is necessary that the htaccess must be setup on Apache first.

28 days ago ·
32282

I think this method only works if the base laravel folder is the webroot. I tried , but it didn't instead this I keep getting a 404 error from Laravel.

7 days ago ·
32548

In laravel 5 You can remove url by following steps:

  1. Rename server.php in your Laravel root folder to index.php
  2. Copy the .htaccess file from /public directory to your Laravel root folder. Source: http://bit.ly/2UEalD0
6 days ago ·