Support the ongoing development of Laravel.io →
Installation Configuration Views
Last updated 2 years ago.
0

You can use .htaccess same

<IfModule mod_rewrite.c>
    RewriteEngine On 
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Or you can use another solution follow step by step

  • Step:1: move all files from public directory to [path_root]/laravel/
  • Step 2: now, no need of public directory, so optionally you can remove it now
  • Step 3: now open index.php and make following replacements
require DIR.'/../bootstrap/autoload.php';

to

require DIR.'/bootstrap/autoload.php';

and

$app = require_once DIR.'/../bootstrap/start.php';

to

$app = require_once DIR.'/bootstrap/start.php';
  • Step 4: now open bootstrap/paths.php and change public directory path:
'public' => DIR.'/../public',

to

'public' => DIR.'/..',
Last updated 2 years ago.
0

The public folder is intended to be the DocumentRoot ("htdocs") of your web server (i.e. Apache) and all the rest of the content outside that folder should not be publicly accessible for security reasons.

It is common, if working on multiple projects, to set up a VirtualHost in Apache to point at your Laravel/public folder (which can then live anywhere on your PC, not necessarily inside "htdocs").

Last updated 2 years ago.
0

Thank you both for the answer. @AndrewBNZ that makes sense.@tuyenlaptrinh i'd like to use the .htaccess solution you offered but it's not working. My file is now configured like this:

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

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)$ public/$1 [L]    (previously this was the line: RewriteRule ^(.*)/$ /$1 [L,R=301])

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

I made the changes you suggested to the Rewrite rule line but it gave me a 404 error.

Any suggestions? My Modrewrite is on and Override is All...

Last updated 2 years ago.
0

You can use .htaccess as a solution.

Or you can solution second to don't use public folder

Last updated 2 years ago.
0

During development I find it significantly easier to just do "php artisan serve" - bypassing all of the issues.

So you'd just run "php artisan serve" from the terminal at the root of your laravel project, and it starts up a development server for you - usually on port 8080 on mine.

Alternatively, you can go into the public folder of your laravel install and run :

php -S localhost:666

which would start the server on port 666. either way works, but the artisan route is easier.

The next is to create a virtual host with the root set to the public folder. Depending upon what development environment you are using, the proces may be slightly varied, but it basically entails editing apache httpd.conf (or equivalent file for nginx).

Last updated 2 years ago.
0

Sorry, I'm not very sure if your problem has been solved.

This was the fix for my Apache server. RewriteBase did the trick!

Create this .htaccess in the public folder:

    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews
        </IfModule>
    
        RewriteEngine On
        RewriteBase /
    
        # Redirect Trailing Slashes...
        RewriteRule ^(.*)/$ /$1 [L,R=301]
    
        # Handle Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    </IfModule>
Last updated 2 years ago.
0

@tuyenlaptrinh thank you again for both of your answers. I think they were elegant. Its just that i'm new to Laravel and if those changes put some out of wack for me, i'd be thrown for a loop. I usually prefer hands off solutions when possible. Also I made a bunch of changes to my public folder address before so it would've been difficult.

@abhiyanp thanks for providing a solution someone as dumb as me could use. This is was very quick and easy as well. Cheers.

Last updated 2 years ago.
0

@heroselohim glad it worked for you and hope it helps the next person.

Last updated 2 years ago.
0

@lilliamsjr glad that the php serve helped you, but I'm pretty sure this problem is not in the .htaccess

I agree with @AndrewBNZ, this should be a VirtualHost bad setup (if there is one).

Here you have a very good tutorial for it: http://laravel-recipes.com/recipes/25/creating-an-apache-virtualhost

You should add this lines at the end of httpd.conf

It should look like this:

    NameVirtualHost * 

    <VirtualHost *>
        ServerName localhost
        DocumentRoot "c:/webserver/site/laravel/public"
        <Directory "c:/webserver/site/laravel/public">
                AllowOverride all
        </Directory>
    </VirtualHost>

Without a virtual host I think you won't achieve that kind of short URLs over XAMPP

Remember to edit the .htaccess as mentioned before.

Last updated 2 years ago.
0

@heroselohim just to be clear.. I still need to create a virtual host, edit my .htaccess file, and add this line to the end of my httpd.conf file even if Php artisan serve gave me the short url I wanted? It was on port 8000 so thats the problem?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.