Other routes rather than default one not working with XAMPP

Viewed 1967

I have my Laravel project, not running on my localhost XAMPP if I use the address "localhost/app/public" I get the main (i.e welcome)page(welcome.blade.php)working but when I write my other route like "localhost/app/public/anyother" it show me error message,404 | Not Found. While the default and all other routes work fine for "php artisan serve".

There are 2 Things I want to know hope you'll not mind it.

1. How to solve this issue for XAMPP on Laravel own application server all routes are accessible fine?

2. Why other routes are not working in local XAMPP while they work fine with "php artisan serve"?

What I found for run Laravel App on XAMPP is:-

Working with xampp:

Go to C:\Windows\System32\drivers\etc\hosts and add a new line like: 127.0.0.1 yoursite.local Go to where XAMPP is installed under xampp\apache\conf\extra\httpd-vhosts.conf Then add a virtual host in the bottom of the file like:

<VirtualHost *:80>

DocumentRoot "PATH_to_laravel_folder/public"  

ServerName yoursite.local  
</VirtualHost>

Is there any other solution without creating Virtual Host if I accept this solution for my point #1? Any other solution if I want to use XAMPP provided URL such as "localhost/app/public"?

2 Answers

Your virtual host are not good. You are forgot the Directory specification tag and not allowing indexing.

Try to edit httpd-vhosts.conf that is located in C:\xampp\apache\conf\extra\httpd-vhosts.conf like this:

# VirtualHost for LARAVEL.DEV

<VirtualHost laravel.dev:80>
  DocumentRoot "C:\xampp\htdocs\laravel\public"
  ServerAdmin laravel.dev
  <Directory "C:\xampp\htdocs\laravel">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
  </Directory>
</VirtualHost>

You can find out more the Apache documentation

<Directory> and </Directory> are used to enclose a group of directives that will apply only to the named directory, sub-directories of that directory, and the files within the respective directories.

In other words Apache web server automatic index generation is enabled with using Options +Indexes or Options Indexes directive.

If a URL which maps to a directory is requested, and there is no DirectoryIndex in that directory, then mod_autoindex will return a formatted listing of the directory.

Solution 1:

Try renaming the server.php in your Laravel project folder to index.php and copy the .htaccess file present inside public directory to your project root folder.

Solution 2:

Copy .htaccess and index.php from public directory to project root folder

Change the index.php file as addressed below:

 //change line 22 to       
 require __DIR__.'/bootstrap/autoload.php';

 //change line 36 to
 $app = require_once __DIR__.'/bootstrap/app.php';

Hope one of the above solution would work well in your case.

Related