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

charlesmun's avatar

.htaccess issues, routes work with index.php on ubuntu 20.04 server

I am running a Laravel 9 application on Ubuntu 20.04. Web server is Apache (Apache2) The application opens nicely, on the default route " route('/') ".

All other routes work only if appended with "index.php". I have tried multiple versions of the .htaccess file but failing to sort this out. Please assist.

Here is the default .htaccess file with the the installation

Options -MultiViews -Indexes
RewriteEngine On

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

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

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

#Sort the index.php routing issue where all routes require the path to have index.php
0 likes
8 replies
charlesmun's avatar

@jlrdw Thanks. Have tried the solution but url not opening unless I add "index.php/..." to the desired route.

jlrdw's avatar

@charlesmun somehow your folder structure is not correct. You need to get it correct and point to public as the document root. If you have modified the folder structure, it is hard to help with these type of problems.

But I can assure you from experience with a proper folder structure everything works correct.

charlesmun's avatar

@jlrdw Thanks. The folder structure was set correctly as I was pointing the virtual host to /var/www/my_site/public folder.

I have marked the solution from @alizadeh as the one that worked for my specific case.

Thank you once again for your assistance.

alizadeh's avatar
alizadeh
Best Answer
Level 4

@charlesmun In my opinion, your .htaccess file does not have permission in apache so you can check this to solve your problem.

go to /etc/apache2/apache2.conf (this may be different in your system find the apache config file in your server ) and search for AllowOverride and you find this for /var/www

<Directory /var/www/>      
    Options Indexes FollowSymLinks       
    AllowOverride None       
    Require all granted   
</Directory>         

you must change None to All.

I should mention if you have a shared host this is different.

2 likes
charlesmun's avatar

@alizadeh Thank you. This resolved the issue and the routes are opening perfectly. I am not on shared hosting so I setup the server from scratch and had ran into that issue.

Just on a different note, may you please explain the logic behind the change above.

Thanks a lot.

alizadeh's avatar

@charlesmun Welcome, As you know .htaccess is used to change some Apache or other Web Server configurations locally, so this must be permitted by the main config file.

This permission for using a .htaccess file as default does not permit because of security reasons. This code changes the permission for using .htaccess in the /var/www path and all subfolders. you can find in apache2.conf some other path. Moreover, you can add some special paths by yourself.

In the end, you must restart your web server to configure the new changes.

1 like

Please or to participate in this conversation.