Laravel on Google Compute Engine with Apache2 RewriteEngine on Returns 404

I’m trying to host this website on google cloud using the compute engine and apache2. Since this is a previously established instance, there are a couple websites in there already and a pre configured .conf file as shown below. Uploading files and other stuffs are fine, and the website run smoothly, however i ran into the /public issue in where if the user didn’t enter domain/public they’d be taken to the project directory index page instead.

i have tried creating the .htaccess file inside the laravel root directory, it got rid of the directory index page but it returns 404 instead. I have checked the routes are indeed listed and can be accessed with the /public even after the RewriteEngine on in .htaccess

lamp-server.conf :

<VirtualHost *:80>
  ServerAdmin [email protected]
  DocumentRoot /var/www/html
  <Directory /var/www/html/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
  ErrorLog ${APACHE_LOG_DIR}/error.log
  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/access.log combined

.htaccess :

RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

404 :
return 404 without public

expected result : return the landing page

issue : server return 404 on existing routes without /public after .htaccess RewriteEngine on

question : How do i fix this so it doesnt return 404 without the /public?

Source: Laravel

Leave a Reply