Laravel 4 removing public from URL
Easiest way is create .htaccess
file in your Laravel root with following content:
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/$1 [L]</IfModule>
It should be redirected easily.
Reference: https://coderwall.com/p/erbaig/laravel-s-htaccess-to-remove-public-from-url
Here's how I did it.
- Edit your Windows Host file - C:\Windows\System32\drivers\etc\hosts
- Edit the Apache vhosts file - Drive-Letter:\xampp\apache\conf\extra\httpd-vhosts.conf
- Add an htaccess file to the laravel/public folder (if its not already there)
- Restart Xampp apache server
Windows can be a real PITA when trying to edit the Hosts file because of the User Account Control. Since I work on all kinds of small hobby projects, I have to edit this file all the time so this is what I do.
- Install PSPad. It loads really fast and you can bookmark files for easy loading/editing. Sublime Text also works well if you load the two files I mentioned above and save the workspace as a new project.
- Right-click on the PSPad (or other editor) program shortcut and choose 'Run as Administrator'. You cannot save changes to the Hosts file unless you do this.
- Open the Windows Host file in the editor. This file does not have a file extension, so you have to choose "All Files" in the File Open dialog to even see the file.
At the bottom of the file, add this:
127.0.0.1 laravel.dev
This tells Windows to point the web browser to localhost whenever you enter laravel.dev in the browser's address bar.
- Save the file.
- Open the xampp Apache httpd-vhosts.conf file.
At the bottom of the file, add this: (I am assuming xampp is installed at the root of the D: drive)
<VirtualHost *:80> ServerName laravel.dev DocumentRoot "D:/xampp/htdocs/laravel/public" <Directory "D:/xampp/htdocs/laravel/public"> </Directory></VirtualHost>
Add an htaccess file to your laravel/public folder (if its not already there). I think the default htaccess file that comes with L4 looks like this:
Options -MultiViewsRewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^ index.php [L]
- Restart your xampp apache server.
- Open a web browser and type in the address bar -
http://laravel.dev
- That will take you to the index.php file in the "public" folder.
- To get to the About page, I think the address would be
http://laravel.dev/about
Move the contents of the /public folder down a level.
You'll need to update the include lines in index.php to point to the correct location. (if it's down a level, remove the '../').