Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jimix's avatar
Level 1

Error 404 : Routes error after deploying on hosting

Hi, I know there is a lot of discussion for this pb but All don't resolve my problem.

My website is on the folder (debian) : var/www/mywebsite/public

My first page was loaded but when I clic to login or register I have the 404 error: "The requested URL /mywebsite/public/login was not found on this server"

I try to :

  • put a ".htaccess" on my public directory with RewriteEngine On
  • Edit apache.conf to put "AllowOverride All" for my directory
  • Create a virtualhost file and enable it (a2ensite)
  • My ".env" was modified with my website informations
  • All grant is ok

I juste see a change, when I edit apache.conf (AllowOverride All), the error 404 has been replaced by an error 500

Could you help me please?

0 likes
13 replies
jimix's avatar
Level 1

noboby resolved this problem????

vinschi's avatar

@jimix this is what I did:

in the public folder (or www depends on the hosting) I have this .htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
    #    Options -MultiViews
    </IfModule>

    RewriteEngine On
    RewriteBase /
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

as you can see I added the RewriteBase / assuming you have all the other stuff in the root folder. Please try and let me know but be aware that I never touched anything else. Cheers

6 likes
Snapey's avatar

aaagggghhh people.. How many times ?

DocumentRoot = public folder and not your Laravel folder

1 like
jlrdw's avatar

@Snapey I think he put the public folder contents in www direct, where as my setup is www = public_html on this server.

laravelup
public_html
-----tjhs
-----------.htaccess
------------index.php
        

where laravelup is main laravel NOT IN public_html, and tjhs is where the public files are.

I think he did

laravelup
public_html
-------.htaccess
-------index.php
        

put the htaccess and index direct into public_html, but not sure.

My RewriteBase is

RewriteBase /tjhs/

And it works. But I use laravel version 5.1. You would think 5.4 would be the same.

Also in my index.php which is under tjhs folder above I have

require __DIR__.'/../../laravelup/bootstrap/autoload.php';
//instead of 
require __DIR__.'/../bootstrap/autoload.php';

and

$app = require_once __DIR__.'/../../laravelup/bootstrap/app.php';
//instead of
$app = require_once __DIR__.'/../bootstrap/app.php';

It's just that simple.

I keep telling the folks to learn how to resolve the paths.

EDIT: I have never used ver 5.4, so for grins I attempted to install it like I do ver 5.1, works exactly the same.

I have everything above (www or whatever) except contents of the public folder that comes with laravel, it's the only stuff under www.

So if folks could just resolve the paths correctly.

jimix's avatar
Level 1

Firstly thanks a lot for your help.

@vinschi ... I edit my .htaccess ... I have the same error

@jlrdw :

I have

public_html

------- Mywebsite

-------------- public

--------------------- .htaccess

--------------------- index.php

------- otherwebsite

On my computer (MAMP server), it's run .... Why I should change My organization?

(For information I use Laraship Pro - Laravel Powerful Admin ... http://laraship.com/manual/)

jimix's avatar
Level 1

@Snapey

"DocumentRoot = public folder and not your Laravel folder"

What do you want to say about this? For my .htaccess file?

jlrdw's avatar

MAIN LARAVEL goes outside of (www, public_html, htdocs, whatever name), period. For grins, I have never used 5.4, I used 5.1. BUT, I installed 5.4, uploaded to godaddy correctly all works 100%.

sloshoutindia's avatar

Hi, I also get some 404 errors on some pages of Sloshout.com, please help me out and let me know how do I resolve the 404 errors. Thanks

mehdisalimi's avatar

you can set htaccess on root directory and set below setting.

.htaccess main domain to subfolder redirect

RewriteEngine on RewriteRule !^public/ /public%{REQUEST_URI}

Please or to participate in this conversation.