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

Indra7667's avatar

Ubuntu Apache non-root route returns 404 not found

I tried to install laravel 10 in /var/www/html on ubuntu server, but I can't access any page other than the root url (it returned apache's "The requested URL was not found on this server")

I've set the documentroot on sites-available/000-default.conf to /var/www/html/public

I set my root .htaccess like this:

    # Displaying php errors
    php_flag display_errors on
    php_value error_reporting 6143

<Directory /var/www/html/>
    Options -Indexes FollowSymLinks MultiViews
    AllowOverride none
    Order allow,deny
    Allow from all
</Directory>

RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]

and left public/.htaccess unchanged like this:

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

    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]
</IfModule>

I've tried adding this to root's .htaccess following an answer on stackoverflow

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

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

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

 <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
    #RewriteCond %{REQUEST_URI} !^public/
    #RewriteRule ^(.*)$ public/$1 [L,QSA]
 </IfModule>

but still no luck.

I'm sure it's apache's configuration problem but I have no idea on how apache configuration work

I need help, did I miss something?

0 likes
8 replies
Indra7667's avatar

@Tray2 I will be completely honest, I don't completely understand.

Is it something like making a new sitename.conf in etc/apache2/sites-available, adding it to etc/hosts, then a2ensite?

if yes then I've tried it but the result is the same. I might did a mistake tho, I'll try tinkering around with it

thanks for the link tho, I love learning from examples

s4muel's avatar
s4muel
Best Answer
Level 50
set the document root and directory directly to the public directory and get rid of the "public" related rewrites
...
 <VirtualHost ...
    DocumentRoot /var/www/html/public

    <Directory /var/www/html/public>
        Options -Indexes
        AllowOverride All
    </Directory>
...
1 like
Indra7667's avatar

@s4muel Still doesn't work.

Is that how it's normally done? if yes then I might need to try reinstalling apache to reset all the config I've tinkered around

Indra7667's avatar

I think I really did messed up my apache's config.

I can't go to any of my registered (ip/server?) in etc/hosts, all of it returned http status 404. I know it worked before (≈4 hours ago)

thanks for the help @tray2 @s4muel

Indra7667's avatar

@Tray2 Sorry for the late answer, I was focused in a formal project so I was away from my personal project

Thank you for the tutorial, I've checked and compared the tutorial you sent with my steps, and apparently I've done everything correctly

Indra7667's avatar

My Laravel Project is working properly in my virtual host after comparing my steps with @tray2 's link and retesting @s4muel 's recommendation in apache2.conf instead of 000-default.conf

Thank you @tray2 and @s4muel for the help (and sorry for the late followup)

1 like

Please or to participate in this conversation.