Apache Mod Rewrite For Laravel

后端 未结 5 1960
野趣味
野趣味 2020-11-29 05:26

I have an installation of Laravel on Wampserver. The directory is as follows:

C:\\wamp\\www\\laravel

Now URLs are like this:

http://localhost/

5条回答
  •  Happy的楠姐
    2020-11-29 06:03

    When testing locally I do one of two things.

    1. Create a new .htaccess below the public directory with the following.

      
          RewriteEngine on
      
          RewriteRule ^(.*)$ public/$1 [L]
      
      
    2. Create a new virtual host. With WAMP you can navigate to C:\wamp\bin\apache\YOUR APACHE VERSION\conf\extra and find your httpd-vhosts.conf file, in there you can see example virtual hosts. Here's one of mine:

      
          DocumentRoot "c:/wamp/www/laravel/public"
          ServerName laravel.dev
          ServerAlias www.laravel.dev
      
      

      Make sure that your vhosts configuration file is being included. Open up your httpd.conf file and search for the vhosts file, uncomment the include line if it's commented out. Then I open the CLI and enter notepad "C:\windows\system32\drivers\etc\hosts" which opens up your hosts file. Underneath the item that mentions localhost place your new host. Here's an example.

      127.0.0.1  laravel.dev
      

      Make sure you restart Apache and bingo, you should be able to navigate to http://laravel.dev and you won't have any annoying public directory. This is how I achieve it, as I prefer the nicer looking virtual host rather then a long winded localhost URL.

    Hope this helps.

提交回复
热议问题