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
You have to enable
mod_rewrite
:and in the
000-default.conf
you should have something like this:this will redirect your website (visit
http://www.example.com
) to the laravel projectadd the following to 000-default.conf, you will then be able to access without any rewrite rules.