Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

812
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda