Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

arronar's avatar

Apache2.4 & Laravel 5.4 with alias in a subfolder doesn't work without /index.php

I've created an alias on apache server conf file (/etc/apache2/mods-enabled/alias.conf) to target the public folder.

Alias /laravel/ "/home/user/dev/web/laravel/public/"

<Directory "/home/user/dev/web/laravel/public/">
        Options Indexes FollowSymLinks MultiViews ExecCGI
        AllowOverride All
        Require all granted
</Directory>

Also, I wrote the following .htaccess

Options -MultiViews

RewriteEngine On

RewriteRule ^(.*)/$ / [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/laravel/(.*) /laravel/index.php/ [L]

Now, when I'm visiting the http://IP/laravel , the index.php is loaded as expected. But if I'm gonna make a call to a GET Route like http://IP/laravel/load_examples I'm getting back a NOT FOUND error.

Instead, if I visit the http://IP/laravel/index.php/load_examples, route loaded as expected.

It seems to me that something's going wrong with the .htaccess and rewrite rules.

I tried everything I found on the SO and other places but couldn't find any solution so far.

Any idea?

0 likes
4 replies
MortenS's avatar

Check if this is missing in your apache.ini:

DirectoryIndex index.php index.html

arronar's avatar

DirectoryIndex was index.html index.php and I changed it into what you suggested but nothing changed.

Also I changed the Rewrite rule to something strange but it seems that apache doesn't apply the rules of the .htacces e.g

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/laravel/(.*) /wtf/index.php/ [L]

with that rule the request didn't change to /wtf/ and in the logs I see

 "GET /laravel/load_examples HTTP/1.1" 404 514

Shouldn't be "GET /wtf/load_examples HTTP/1.1" 404 514 ?

MortenS's avatar

Hmm... Are you sure mod_rewrite is even enabled? Try adding some gibberish to the top of the .htaccess file. This should cause a 500 error. If it doesn't it doesn't, it means apache isn't reading the file.

Just out of curiosity - wouldn't it be easier to set up a VirtualHost in stead of using the IP?

arronar's avatar

It indeed cause a 505 error and rewrite module seems to be loaded

 $sudo a2enmod rewrite 
 Module rewrite already enabled

As for the VirtualHost, I don't want to connect the server with a domain and I suppose that this is a bottleneck in order to use the VirtualHost. Unless I'm wrong.

Please or to participate in this conversation.