19

I have this structure:

My domain: www.example.com

and this is my laravel's project folder: http://www.example.com/project

and I would like to redirect to http://www.example.com/project/public

I know this answer has been answered before but I try to implement it and not work for me.

Sorry for my english, I just speak spanish

Andres Ruales
  • 371
  • 1
  • 2
  • 12

5 Answers5

27

For htaccess

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !project/public/
RewriteRule (.*) /project/public/$1 [L]

Put it into your public_html/ or www/ folder where is the root of example.com/

Germanaz0
  • 914
  • 8
  • 18
  • 1
    Somehow this doesn't work with localhost as URL. (The 3rd line is the issue I believe, not sure why) – Ben Fransen Dec 14 '15 at 22:12
  • As @BenFransen said above this didn't work for me in localhost. Just changed to the dev linux machine hostname and it's working fine now. – cdsaenz Oct 11 '20 at 03:06
9

rename /server.php to index.php

Basem Olimy
  • 767
  • 7
  • 10
  • 3
    This works, BUT you have to edit all the the paths to CSS and JS files. Less practical than the .htaccess solution. – Nebster Jul 03 '17 at 10:23
0

I created this php script and placed in the in the root of the laravel directory:


    $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    header("Location: " . $actual_link . "public/index.php");

Erhnam
  • 901
  • 2
  • 13
  • 23
0

To serve the public directory on the default domain in a Laravel application (version >8), you can follow these steps:

Go to the root directory of your Laravel application (usually named public_html). Create a file called .htaccess. Ensure that you have the option to show hidden files toggled on. If you don't see the file, click on "Settings" in the top right corner and toggle "Show Hidden Files" or "Show Dotfiles." Open the .htaccess file you created and add the following code:

<IfModule mod_rewrite.c>     <IfModule mod_negotiation.c>         Options -MultiViews -Indexes     </IfModule>
    RewriteEngine On

    # Handle Authorization MemberHeader
    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]

    # Remove public URL from the path
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^(.*)$ /public/$1 [L,QSA]

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

  RewriteCond %{REQUEST_URI} !^/public/   RewriteRule ^(.*)$ /public/$1 [L,QSA]
-1

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

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 14 '23 at 20:31