Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

811
Views
Problem redirecting to /public folder in a Laravel project on Apache

I have the following situation with a Laravel project. I uploaded the project to a Linux Server in the /var/www/html/tup folder.

I can access the site with the link http://www.example.com/tup/public as shown in this image (First Image)

I want to access directly without entering the public in the URL i. e. http://www.example.com/tup

I tried with a .htaccess file in the main folder of the project:

<IfModule mod_rewrite.c>
# That was ONLY to protect you from 500 errors
# if your server did not have mod_rewrite enabled

RewriteEngine On
# RewriteBase /
# NOT needed unless you're using mod_alias to redirect

RewriteCond %{REQUEST_URI} !/public
RewriteRule ^(.*)$ public/$1 [L]
# Direct all requests to /public folder

</IfModule>

But when I enter to http://www.example.com/tup Laravel throws a 404 Not Found error (404 error Image). I have to write http://www.example.com/tup/index.php for Laravel to redirect me like in this image.

It seems that the index.php file is not being detected

In the public folder a I have another .htaccess file:

DirectoryIndex index.php index.html
<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 already modified the apache2.conf file and set all the AllowOverride to All and enabled mod_rewrite as well.

I also added this configuration in the apache2.conf:

<Directory /var/www/html/tup/public/>
    DirectoryIndex index.php
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

I would greatly appreciate any kind of help.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You have to enable mod_rewrite:

sudo a2enmod rewrite
sudo service apache2 restart

and in the 000-default.conf you should have something like this:

<Directory /var/www/html/tup/public/>
    DirectoryIndex index.php
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    Require all granted
</Directory>

this will redirect your website (visit http://www.example.com) to the laravel project

over 4 years ago · Santiago Trujillo Report

0

add the following to 000-default.conf, you will then be able to access without any rewrite rules.

    DocumentRoot /var/www/html/tup/public

    
    <Directory /var/www/html/tup/public>
        Options FollowSymLinks MultiViews 
        Require all granted
    </Directory>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!