skip to Main Content

Hope you guys are well, I have faced a problem deploying my laravel project on Cpanel. When I am hit my route URL or a root URL then it show me "404 not found"

This is the root url : https://laravel.tamimikbal.com/project1/

I have written this code on my root .htaccess file

RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

And this the public/.htaccess file

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

2

Answers


  1. The .htaccess is not redirecting properly to the public directory. I can access and navigate on your site using "https://laravel.tamimikbal.com/project1/public/&quot;.

    Try this as the contents of the .htaccess file in your root:

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteRule ^(.*)$ public/$1 [L]
    </IfModule>
    
    Login or Signup to reply.
  2. I can better understand if you put how is the routing url should be looks like
    anyway you can try this code:

        RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    RewriteBase /
    

    while you don’t have www. and https is activated on your domain you can use this code to make redirect from www. to none www and from http to https

        RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www. [NC]
    RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
    

    the rout request and file directory you can use this code

        RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !.*.(ico|gif|jpg|jpeg|png|js|css|webp|JP2)
    RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
    

    if you want to redirect you system files to 404 page edit this code and replace your system folder and your 404 routing page

    RewriteRule ^system/(.*) index.php?route=your 404 page [L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search