Laravel 4 removing public from URL

后端 未结 20 2175
一个人的身影
一个人的身影 2020-11-29 04:33

So, I\'m running xampp on Windows. I\'m currently trying to get familiar with the laravel framework. Now, when thats pointed out. How can i be able to access my laravel appl

20条回答
  •  甜味超标
    2020-11-29 04:42

    Here's how I did it.

    1. Edit your Windows Host file - C:\Windows\System32\drivers\etc\hosts
    2. Edit the Apache vhosts file - Drive-Letter:\xampp\apache\conf\extra\httpd-vhosts.conf
    3. Add an htaccess file to the laravel/public folder (if its not already there)
    4. 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)

      
        ServerName laravel.dev
        DocumentRoot "D:/xampp/htdocs/laravel/public"
        
        
      
      
    • 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 -MultiViews
      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^ 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

提交回复
热议问题