2

Here's is My Laravel-5.4 code that i am facing problem. I had created test laravel project with two pages home & about us and mapped the file path using Apache v-host(www.test.com)
When i hit www.test.com it loads correctly to the index page but when i try to hit www.test.com/about It showing 404 error .But when i hit like this url www.test.com/index.php/about page loads properly I don't know its problem is in my code or Apache configuration or any other

controller:

public function index(){
    return view('pages.index');
}
public function about(){
    return view('pages.about');
}

Route :

// Home Page
Route::get('/','pagesController@index');
// About Us Page
Route::get('/about','pagesController@about');  

Apache conf:

   ServerAdmin webmaster@localhost
   ServerName test.com
   ServerAlias www.test.com
   DocumentRoot /var/www/html/test/public/

.htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Hiren Gohel
  • 4,942
  • 6
  • 29
  • 48
Harish Karthick
  • 710
  • 2
  • 12
  • 26

2 Answers2

5

You probably have an issue with mod_rewrite that is not enabled.

Try to enable it with a2enmod rewrite and then restart apache /etc/init.d/apache2 restart

Give a look to that answer.

OR

If it's not working.
This may come from Apache conf : etc/apache2/httpd.conf.
This article will explain it better than me.

You may need to edit :

<Directory "/var/www/html">
    ...
    AllowOverride None
    ...
</Directory>

To

<Directory "/var/www/html">
    ...
    AllowOverride All
    ...
</Directory>

And restart apache /etc/init.d/apache2 restart

OR

If it's still not working try to do some chmod 0755 on your Laravel's project.

3

Do you have mod_rewrite installed and enabled on apache? In order to use mod_rewrite you can type the following command in the terminal:

a2enmod rewrite

Restart apache2 after

/etc/init.d/apache2 restart

or

service apache2 restart

This is the .htaccess I have on my public/ directory:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Also, editing /etc/apache2/sites-enabled/000-default

<Directory /var/www/>
   Options Indexes FollowSymLinks MultiViews
   AllowOverride All
   Order allow,deny
   allow from all
</Directory>
Hiren Gohel
  • 4,942
  • 6
  • 29
  • 48