Laravel and Apache2 : unable to correctly use redirects

I have an issue with Laravel. On an intranet Apache 2.4.10 Webserver runing with Debian 8.5, named fmbsrv130, I would like to install a Laravel Project named sentinelle.

So Laravel installation is OK, I can access to it with http://fmbsrv130/sentinelle/ (I have the welcome page of Laravel). But if I try to go to http://fmbsrv130/sentinelle/1 (that does not exists), I have 404 from Apache2 that says “The requested URL /home/webadmin/sentinelle/public/index.php was not found on this server.” If I try to access http://fmbsrv130/sentinelle/index.php/1 I have the 404 from Laravel : “Sorry, the page you are looking for could not be found.
1/1 NotFoundHttpException in RouteCollection.php line 161: …”

rewrite_mod is correctly enabled in Apache.

Here is config file of Apache (000-default.conf in sites-available) :

Alias "/sentinelle" "/home/webadmin/sentinelle/public/"

    <Directory "/home/webadmin/sentinelle/public/">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

For testing, if I try to modify .htaccess file from public folder of Laravel with
RewriteEngine On
RewriteRule ^.*$ htaccess_tester.php

(htaccess_tester.php is a file that is used to test content of .htaccessfile (see it on GitHub) and is currently into public folder), I have Apache2 404 error message The requested URL /home/webadmin/sentinelle/public/htaccess_tester.php was not found on this server.

Is it an issue from .htaccess file OR an issue from Apache2 config OR an issue from Laravel config OR a file access right ?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

is your mod_rewrite enabled on your apache2 please confirm it should be enabled to .htaccess work and in your .htaccess file add default laravel .htaccess content

<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>

also if that doesn’t work try to remove your index.php out of public directory and place it in root directory at /sentinell and modify .htaccess to RewriteRule ^ public/index.php [L] that should do the trick

Method 2

OK so finally I found a solution by doing some modifications : first one is .htaccess file into public folder:

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

    RewriteEngine On
    RewriteBase /sentinelle/

    # 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>

(Adding RewriteBase /sentinelle/)

And the second one was into default.conf Apache file :

Alias /sentinelle /home/webadmin/sentinelle/public/

<Directory "/home/webadmin/sentinelle/public">
    AllowOverride All
    Order allow,deny
    allow from all
    Require all granted
</Directory>

It solved the issue described into this topic, I’ll open another one because now I have issue with last “/” in address 🙂


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x