THat is not the way to change the document root, I would suggest creating a virtual host instead the actually has the document root set to the public directory.
Mar 19, 2025
8
Level 1
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?
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
Please or to participate in this conversation.