PHP - How To Remove - Public - From A Laravel URL - Stack Overflow
PHP - How To Remove - Public - From A Laravel URL - Stack Overflow
2024 Developer survey is here and we would like to hear from you! Take the 2024 Developer Survey
I don't want to run a VM, this just seems awkward when switching between projects.
I don't want to set my document root to the public folder, this is also awkward when switching
between projects.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
In Laravel 4 I could move the contents of the public folder into the root. The structure of Laravel 5
is quite different and following the same steps completely broke Laravel (the server would only
return a blank page).
Share Improve this question Follow edited Apr 11, 2023 at 15:25 asked Feb 6, 2015 at 11:13
TylerH user1537360
21.1k 72 78 105 4,791 6 26 22
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 1/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
1 It seems to work by just modifying the paths in the index.php file, but I'm new to Laravel so obviously can't
comment on whether this is stable / safe. – user1537360 Feb 6, 2015 at 13:06
The other folders/files are supposed to be underneath your document root. – Mike Rockétt Feb 7, 2015 at
18:04
laravel remove public from url – user3151197 Sep 27, 2017 at 16:30
4 Most of the responses on this page are incredibly bad practice. The ONLY secure solution is to change the
document root of your web host to be the public folder. If you are on a server that only publishes the
public_html folder, then delete this and create a new public_html symlink that points to and aliases the
Laravel public folder. – Snapey Mar 22, 2022 at 22:32
2 A public folder is there to be exposed at the document root and nothing else. Not doing so opens you
to security issues between the private storage being accessible, the env file and other sensible files.
Change your document root!, there is no valid reason not to do this elsewhere than a local environment,
it's like not hashing a password in the database – Tofandel Aug 31, 2022 at 10:25
2. Copy the .htaccess file from /public directory to your Laravel root folder.
Share Improve this answer Follow edited Apr 11, 2023 at 14:09 answered Feb 26, 2015 at 6:32
TylerH Asfaq Tamim
21.1k 72 78 105 5,687 6 23 29
23 Please review other answers creating just .htacess file in your root directory, because this answer can
expose sensitive information (like .env file) – mauronet Nov 21, 2020 at 0:02
15 Your site you be available for hackers cos .env file we be viewed for everyone . – Abd Abughazaleh Nov 22,
2020 at 11:27
@AbdAbughazaleh What if you change .env file permission to 600? – Mohammad Salehi May 12, 2022 at
9:13
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 2/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
291 PLEASE NOTE when serving a Laravel project with Docker: you won't need to do any of this. Only
use this option when your root (or more commonly: public_html ) directory of your website is
your Laravel project (this is not the case when you're using Docker).
DON'T!
YOU REALLY SHOULD NOT rename server.php in your Laravel root folder to index.php and
copy the .htaccess file from the /public directory to your Laravel root folder!!!
This way everyone can access some of your files ( .env for example). Try it yourself. You don't
want that!
DO
Instead, you should create an .htaccess file in your root like this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]
This will silently rewrite all your base URIs to the /public folder. Even all Headers, for example
the HTTP Authorization Header, and all optional URI parameters will silently be passed on to the
/public folder as well.
Share Improve this answer Follow edited Apr 11, 2023 at 14:05 answered Nov 28, 2018 at 10:13
TylerH Derk Jan Speelman
21.1k 72 78 105 11.7k 4 31 46
1 Hello, @DerkJanSpeelman I'm trying to upload my laravel files inside a subfolder in my hosting like:
(example.com/projects/laravel/blog) in that case, visitors have to visit
example.com/projects/laravel/blog/public, so that I put a .htaccess file with your code in the blog folder
root and want it to redirect to the public folder. But it's not working. Here is the Error occurring: The
requested URL /public/ was not found on this server. How can i solve this ? – Shovan Aug 21, 2019 at 6:36
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 3/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
1 @RaitisKupce and Riosant medium.com/@crocodile2u/… – Derk Jan Speelman Dec 28, 2020 at 14:01
1 @logudotcom if you want to access certain static files on your website, you need to give access to them.
You can do this with htaccess. I strongly suggest to look at the htaccess docs developer.mozilla.org/en-
US/docs/Learn/Server-side/… – Derk Jan Speelman Dec 2, 2021 at 9:47
2 @Tofandel The goal is not to "expose what's not public to the public", it is to remove /public/ from the
URL. One of the easiest and most shared methods to accomplish that just happens to be a way that's not
secure, and people tend to do what's easiest/most common because they don't know any better. – TylerH
Apr 11, 2023 at 15:27
2. Copy the .htaccess from public folder to root folder (like rimon.ekjon said below)
3. Changing .htaccess it a bit as follows for statics:
RewriteEngine On
If there are any other static files needed just add the extension to the previous declared list
Share Improve this answer Follow edited Jun 9, 2023 at 22:16 answered Sep 15, 2015 at 7:57
miken32 ka_lin
42.5k 16 117 162 9,382 6 36 57
1 This for me worked like a bang! It basically solves the problem where no routes work except homepage
and then if you try the solution by Derk, it would then work, but not for all the assets and images. This,
fixed the routes, and also fixed the assets and images. Thanks a lot. :) – Leutecia Jan 2, 2023 at 16:35
4 Congratulations, now the world can access your app's configuration files. – miken32 Jun 9, 2023 at 22:17
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 4/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
In Laravel 5.5 create .htacess file in your root directory and placed the following code:- Reference
Link
136
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
</IfModule>
Share Improve this answer Follow answered Jan 29, 2018 at 4:11
Raham
4,881 3 25 28
Thanks this is work for me. But I want to know it has any security issue or not. – rahul singh Chauhan Aug 2,
2018 at 5:58
3 What does this rule RewriteRule ^ ^$1 [N ] do? – gonzo Sep 30, 2018 at 10:02
1 on chained view resources, such as a dashboard with a admin.something.something that doesnt work. Any
modification has to be done on the route file? – Luiz Wynne Jun 1, 2019 at 15:18
1 @LuizWynne take a look at my answer – Derk Jan Speelman Aug 1, 2019 at 9:21
1 Just wondering how to avoid /public to be recognized too as a valid url.. – cdsaenz Mar 19, 2022 at 2:29
Create an .htaccess file in root directory and place code something like below. However, this will
still allow your .env file to be accessible via URL, so it is not secure.
54
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 5/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
Share Improve this answer Follow edited Apr 11, 2023 at 15:28 answered Jan 20, 2019 at 9:42
TylerH Pallav Nagar
21.1k 72 78 105 627 6 5
4 it's working fine, but still .env file accessible directly from URL. – Manoj Singh Dec 19, 2019 at 9:13
@ManojSingh, what is the URL to access the .env file ? – Istiaque Ahmed Jun 25, 2023 at 5:33
@ManojSingh .env will not be accessible publicly, this is a secure way of doing it. – Pallav Nagar Jan 24 at
5:34
Easy way to remove public from laravel 5 url. You just need to cut index.php and .htaccess from
public directory and paste it in the root directory,thats all and replace two lines in index.php as
45
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
Note: The above method is just for the beginners as they might be facing problem in setting up
virtual host and The best solution is to setup virtual host on local machine and point it to the
public directory of the project.
Share Improve this answer Follow edited Sep 22, 2019 at 17:19 answered Apr 29, 2015 at 11:00
Muhammad Sadiq
1,145 11 14
1 After that css not load, bcoz all css are in public and the public is removed from url – Mr. Tomar Oct 1, 2016
at 5:04
2 You can put "public/" before the js or css files while loading, eg Html::script("public/js/....."); --But the best
solution would be virtual host... – Muhammad Sadiq Oct 3, 2016 at 7:07
This answer is not recommended because it edits vendor-provided files. Instead, handling it via a
change to your .htaccess file is recommended.
41
rimon ekjon said:
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 6/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
Rename the server.php in your Laravel root folder to index.php and copy the .htaccess
file from /public directory to your Laravel root folder.
This worked, but when I made this change, all resource files in the /public directory couldn't be
found, and request URLs didn't work, because I used an asset() helper.
Share Improve this answer Follow edited Apr 11, 2023 at 15:20 answered Sep 11, 2015 at 9:16
TylerH Miron
21.1k 72 78 105 1,057 2 18 32
4 This is not a good way to resolve this problem, as you are trying to update in vendors directory which is
not good practice. – Shadman Jan 25, 2018 at 6:56
1 you only need to add RewriteRule ^(.*)$ public/$1 [L] in your .htaccess file which you have
copied from public directory, by removing this line RewriteRule ^(.*)/$ /$1 [L,R=301] – Shadman
Jan 25, 2018 at 7:17
Who is Rimon Ekjon and where did you see them say this quote? – TylerH Apr 11, 2023 at 14:29
36 <IfModule mod_rewrite.c>
RewriteEngine On
The above code works on the root public_html folder. Having said that your core laravel file
should be inside the public_html folder, if your directory looks like public_html/laravelapp/public
and if you put the above code inside laravelapp it won't work. Therefore you must copy all your
core files into public_html and put the .htaccess file there.
If you want to keep the code in a subdirectory then you can create a subdomain then this code
will work for that also.
Share Improve this answer Follow edited Apr 11, 2023 at 15:21 answered Dec 12, 2017 at 11:57
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 7/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
TylerH Abhinav Saraswat
21.1k 72 78 105 809 8 13
What's the flaws with using this method? – Script47 Oct 10, 2018 at 23:40
@DeepeshThapa If you want that to work, you simply need to modify the .htaccess file so it works with
subdirectories. – Derk Jan Speelman May 8, 2019 at 6:16
I have this in my .htaccess folder in my root public_html folder but I am still getting /public at the end of
my url. ## Redirect to public folder <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L] ##SSL Code from STO RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%
{HTTP_HOST}%{REQUEST_URI} [L,R=301] </IfModule> Any ideas? – CodeConnoisseur Jul 4, 2019 at 16:14
1) I haven't found a working method for moving the public directory in L5. While you can modify
some things in the bootstrap index.php , it appears several helper functions are based on the
23 assumption of that public directory being there. In all honestly you really shouldn't be moving
the public directory.
2) If your using MAMP then you should be creating new vhosts for each project, each serving
that projects public directory. Once created you access each project by your defined server name
like this :
http://project1.dev
http://project2.dev
Share Improve this answer Follow edited Dec 28, 2018 at 19:51 answered Feb 8, 2015 at 1:38
Jignesh Joisar Jeremy Schaffer
14.6k 5 64 59 426 4 10
step 1.copy all file from public and paste on root directory
14
step 2.open index.php file replace with
require __DIR__.'/../bootstrap/autoload.php';
to
require __DIR__.'/bootstrap/autoload.php';
and
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 8/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
to
Share Improve this answer Follow edited Dec 28, 2018 at 19:54 answered Feb 11, 2015 at 8:17
Jignesh Joisar piyush patel
14.6k 5 64 59 191 7
Hi, I have tried your method, performed the above steps but it shows the following errors: Warning:
require_once(D:\Projects\laravel/public/index.php): failed to open stream: No such file or directory in
D:\Projects\laravel\server.php on line 21 Fatal error: require_once(): Failed opening required
'D:\Projects\laravel/public/index.php' (include_path='.;C:\xampp\php\PEAR') in
D:\Projects\laravel\server.php on line 21 – Ali Shahzad Mar 8, 2015 at 7:26
1 This is not a perfect answer, rather it is a much unsecure way. – user10678889 Dec 20, 2019 at 13:11
Here is the Best and shortest solution that works for me as of may, 2018 for Laravel 5.5
1. just cut your .htaccess file from the /public directory to the root directory and replace it
13
content with the following code:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 9/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
Share Improve this answer Follow edited Mar 23, 2019 at 11:15 answered May 17, 2018 at 9:46
Udhav Sarvaiya tony pro
9,872 13 57 66 425 3 12
Let's say you placed all the other files and directories in a folder named 'locale'.
11
require __DIR__.'/../bootstrap/autoload.php';
require __DIR__.'/locale/bootstrap/autoload.php';
Share Improve this answer Follow edited Feb 19, 2015 at 17:26 answered Feb 19, 2015 at 15:39
Angelo Joseph Salvador
352 5 19
BEST Approach: I will not recommend removing public, instead on local computer create a
virtual host point to public directory and on remote hosting change public to public_html
10 and point your domain to this directory . Reason, your whole laravel code will be secure
because its one level down to your public directory :)
METHOD 1:
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 10/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
METHOD 2:
This work well for all laravel version...
/laravel/
... app
... bootstrap
... public
... etc
require DIR.'/../bootstrap/autoload.php';
to
require DIR.'/bootstrap/autoload.php';
and
to
to
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 11/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
Share Improve this answer Follow edited Dec 15, 2018 at 5:52 answered Sep 14, 2016 at 12:16
Wasim A.
9,830 22 93 121
Its ok for everything. but artisan command is not working, just it show "Could not open input file: artisan" .
Is there any suggestion ? – Kabir Hossain Jan 29, 2017 at 5:45
1 This method worked, If you are OK to expose your database credentials to users. localhost/laravel/.env
– MasoodRehman Dec 23, 2017 at 14:43
I would like to add to @Humble Learner and note that the proper location to "fix" the url path for
assets is /Illuminate/Routing/UrlGenerator.php/asset().
8
Update the method to match:
This will fix scripts, styles and image paths. Anything for asset paths.
For XAMPP user to remove public from url without touching laravel default filesystem is to set a
Virtual Host for your application to do this jsut follow these steps
6
1. Open the XAMPP control panel application and stop Apache. Be aware that late Windows
machines might run it as a service, so check the box to the left of the Apache module.
4. Around line 19 find # NameVirtualHost *:80 and uncomment or remove the hash.
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 12/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
<VirtualHost *>
ServerAdmin admin@localhost.com
DocumentRoot "C:/xampp/htdocs" # change this line with your htdocs folder
ServerName localhost
ServerAlias localhost
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
6. Now you can copy and paste the code above below to add your Virtual Host directories. For
example I’m working on a site called Eatery Engine so the following snippet will allow me to
work with sub-domains on my local install:
<VirtualHost eateryengine.dev>
ServerAdmin admin@localhost.com
DocumentRoot "C:/xampp/htdocs/eateryengine" # change this line with your
htdocs folder
ServerName eateryengine.dev
ServerAlias eateryengine.dev
<Directory "C:/xampp/htdocs/eateryengine">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
7. Next head over to your Windows host file to edit your HOSTS. the file will be located at
C:/Windows/System32/drivers/etc/hosts , where hosts is the file. Open it with notepad.
127.0.0.1 localhost
Share Improve this answer Follow edited Jan 27, 2018 at 9:05 answered Jul 19, 2016 at 16:47
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 13/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
pirho sunny kashyap
12k 13 52 74 2,273 2 19 29
There is always a reason to have a public folder in the Laravel setup, all public related stuffs
should be present inside the public folder,
5
Don't Point your ip address/domain to the Laravel's root folder but point it to the public
folder. It is unsafe pointing the server Ip to the root folder., because unless you write
restrictions in .htaccess , one can easily access the other files.,
Just write rewrite condition in the .htaccess file and install rewrite module and enable the
rewrite module, the problem which adds public in the route will get solved.
Share Improve this answer Follow answered Apr 19, 2017 at 10:29
Reiah Paul Sam
555 6 16
Create new file called .htaccess in root project folder and place the below code inside it :
5 <IfModule mod_rewrite.c>
#Session timeout
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
</IfModule>
Note: If you changed server.php to index.php you also should rename it in above code
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 14/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
3 </IfModule>
RewriteEngine On
To use mod_rewrite from within .htaccess files (which is a very common use case), edit the default
VirtualHost with
<Directory "/var/www/html">
AllowOverride All
</Directory>
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 15/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
mujuonly
11.7k 5 46 78
Problem is if you type /public and it will still be available in the url, therefor i created a fix which
should be placed in the public/index.php
3
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
if(file_exists(__DIR__.'/public'.$uri)){
}else{
this peace of code will remove public from the url and will give a 404 and then redirects to the url
without the public
Share Improve this answer Follow answered Aug 13, 2019 at 18:52
Paul De Zwaan
77 5
I know that are are a lot of solution for this issue. The best and the easiest solution is to add
.htaccess file in the root directory.
3
I tried the answers that we provided for this issue however I faced some issues with auth:api
guard in Laravel.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 16/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
Create the .htaccess file in your root directory and add this code. And everything goes right
Create .htaccess file in root directory and place code something like below.
3 <IfModule mod_rewrite.c>
#Session timeout
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
</IfModule>
Create .htaccess file in /public directory and place code something like below.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 17/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
Share Improve this answer Follow answered Jun 19, 2020 at 6:05
Ghanshyam Nakiya
1,672 19 24
Create an .htaccess file in your root DIR and paste the below code.
3 RewriteEngine On
Share Improve this answer Follow edited Apr 11, 2023 at 14:13 answered Sep 26, 2020 at 23:25
TylerH newbdeveloper
21.1k 72 78 105 394 3 11
Even if i do not recommend putting Laravel on the root folder there are some cases when it
could not be avoided; for those cases the above methods do not work for assets so i made a
2 quick fix changing the htaccess: after copying server.php to index.php edit the .htaccess file like
so:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
This was a quick fix i had to make so anyone is welcome to upgrade it.
Share Improve this answer Follow answered Sep 13, 2017 at 20:12
Plokko
764 2 11 23
Everything can be done just editing the .htaccess using mod_rewrite and four simple rules.
2. Edit it as below
I commented everything, so it should be clear (I hope) also to those who have never used
mod_rewrite (not that I'm an expert, all the opposite). Also, to understand the rules, it must be
clear that, in Laravel, if Bill connects to https://example.com , https://example.com/index.php is
loaded. This file just contains the command header("refresh: 5;
https://example.com/public/") , which sends the request to
https://example.com/public/index.php . This second index.php is responsible to load the
controller and other stuff.
# IfModule prevents the server error if the app is moved in an environment which
doesn’t support mod_rewrite
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 19/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
# RULES ORIGINALLY IN public/.htaccess ---
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
</IfModule>
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 20/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
The following rule (originally in public/.htaccess ) can be deleted. The same rule, in fact, is
explicit in a more detailed way in the last two rules.
Share Improve this answer Follow edited Apr 11, 2023 at 15:37 answered Jan 27, 2018 at 16:36
TylerH Brigo
21.1k 72 78 105 1,106 1 12 36
Another method that I use is to create a symbolic link (in Linux, don't know about Win) using the
ln command in htdocs or www i.e. ln projectname/public project The site is thus accessible via
0 localhost/project
Share Improve this answer Follow answered Nov 15, 2016 at 15:26
Eli Makumba
89 1 1
You can remove public keyword from url using various methods.
1) If you are using dedicated hosting and you have root access then You can remove public
0
keyword from url using Virtual Host. You should give DocumentRoot path with public. So this will
start index from public directory and remove it from url.
<VirtualHost *:80>
ServerAdmin info@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/{yoursourcedirectory}/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
2) If you dont have root access of your hosting then you should genarate a new .htaccess file in
your root directory and put the code as below
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 21/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
Share Improve this answer Follow answered Dec 27, 2018 at 6:49
Vinod Joshi
176 1 8
I have read some article before and it's working fine but really don't know is safe or not
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
to
require __DIR__.'/local/bootstrap/autoload.php';
$app = require_once __DIR__.'/local/bootstrap/app.php';
Share Improve this answer Follow edited Apr 11, 2023 at 14:14 answered Feb 10, 2017 at 15:31
TylerH Yousef Altaf
21.1k 72 78 105 2,719 4 49 74
Just edit your .htaccess in the root folder and write the following code. Nothing else required
-1
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 22/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
<IfModule php7_module>
php_flag display_errors Off
php_value max_execution_time 30
php_value max_input_time 60
php_value max_input_vars 1000
php_value memory_limit -1
php_value post_max_size 8M
php_value session.gc_maxlifetime 1440
php_value session.save_path "/var/cpanel/php/sessions/ea-php71"
php_value upload_max_filesize 2M
php_flag zlib.output_compression Off
</IfModule>
Share Improve this answer Follow edited Mar 23, 2019 at 11:24 answered Jan 9, 2019 at 6:47
Udhav Sarvaiya AKHIL RAJ
9,872 13 57 66 39 5
add .htaccess file to you root folder and paste the following code and replace yourdomainname
with your own domain name
-1
RewriteEngine on RewriteCond %{HTTP_HOST} ^(www.)?yourdomainname$ RewriteCond %
{REQUEST_URI} !^/public/
Share Improve this answer Follow answered Oct 21, 2019 at 6:39
Khem Raj Regmi
2,220 20 22
1. open vendor\laravel\framework\src\Illuminate\Foundation\helpers.php
-1
2. goto line 130
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 23/24
6/11/24, 6:31 PM php - How to remove /public/ from a Laravel URL - Stack Overflow
Share Improve this answer Follow edited Apr 11, 2023 at 15:38 answered Aug 14, 2018 at 21:19
TylerH Ferhat KOÇER
21.1k 72 78 105 3,987 2 27 26
4 Rule number 1: Never edit a core file. Even if it looks easy and nice now, you will pay later.
– Janaka Dombawela Nov 9, 2018 at 10:48
@JanakaDombawela i don't think that way because: – Ferhat KOÇER Dec 13, 2018 at 19:32
@JanakaDombawela I don't think that way because: Senerio 1: If developer a experienced : Open source
code is for this job Senerio 2: If developer is a junior, developer must do edit to source code for gain
experience – Ferhat KOÇER Dec 13, 2018 at 19:39
Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question.
The reputation requirement helps protect this question from spam and non-answer activity.
https://stackoverflow.com/questions/28364496/how-to-remove-public-from-a-laravel-url 24/24