skip to Main Content

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.

2

Answers


  1. 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

    Login or Signup to reply.
  2. 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>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search