1

I've set up my VPS server and am trying to set up a Laravel project. I have a /public_html/ folder with an index.html that's shown when visiting the website URL.

  • I have a laravel project in: /public_html/project_one/
  • The original index.php is located in /public_html/project_one/public/index.php

I want the website to show to Laravel project_one by default, but since yesterday I literally googled this for 4 hours, I tried every solution on stackoverflow, nothing worked... I think I've tried over 10 versions of .htaccess I could find.

The question:

Does anyone know how to setup the .htaccess inside /public_html/ so it redirects to my Laravel project in /public_html/project_one/ ? And have the .htaccess inside /project_one/public/ be compatible with this?

I want the main url to show the Laravel project. So www.mainurl.com is Laravel's project_one/public/index.php file. I do not want /project_one/ to be written in the URL!

Just out of curiosity, if I now visit: www.mainurl.com/project_one I get a 403 forbidden.

Failed solutions

In /public_html/ I tried to add .htaccess with:

DirectoryIndex index.php

#Redirect to /project_one/public if you haven't already and the IP is okay
RewriteCond %{REMOTE_ADDR} ^1\.2\.3\.4*
RewriteCond %{REQUEST_URI} !^/project_one/public
RewriteRule ^(/lucaphoto)?(.+) /project_one/public$2 [L]

#if IP does not match and you ARE in the folder, then Redirect to root
RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4*
RewriteCond %{REQUEST_URI} ^/project_one/public
RewriteRule .? / [R=301,L]

This gives me something really strange:

  1. On Chrome: it redirects me to www.mainurl.com/project_one -> And then gives me a 403 forbidden error...
  2. On safari: it redirects me nowhere but gives me this error:

Forbidden. You don't have permission to access / on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Laravel's original .htaccess File

By the way, Laravel has an original .htaccess file at /project_one/public/.htaccess. And it looks like this:

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

    RewriteEngine On

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

Someone said this was a duplicate for: Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to Ask But it's really not. I read that whole article, tried some tweaks, couldn't solve the problem... : (

mesqueeb
  • 111
  • 5

0 Answers0