Back

Removing PUBLIC from URL


behnampmdg3 posted 5 years ago

Hi guys;

I find it very difficult to remove public from url. Some say I have to set up virtual host, some say only an htaccess is enough and some offer some really long solutions.

I am on XAMPP and my file system looks like this .

I want a solution that I can easily upload my laravel_project directory and it still works fine.

Thanks

supernoctem replied 5 years ago

Hi,

Easiest way is to create a .htaccess file in your laravel root directory, then add this into the file:

<IfModule mod_rewrite.c>
    RewriteEngine On

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

Better option (recommended for production environments), is to set you document root for apache (xampp) to the public folder, and not the laravel folder.

Source: https://coderwall.com/p/erbaig Source2: Personal Experience

thepsion5 replied 5 years ago

Change your document root in your apache config from "your/path/to/laravel" to "your/path/to/laravel/public"

extjac replied 5 years ago

thepsion5 said:

Change your document root in your apache config from "your/path/to/laravel" to "your/path/to/laravel/public"

AGREE

aouliet replied 5 years ago

supernoctem said:

Hi,

Easiest way is to create a .htaccess file in your laravel root directory, then add this into the file:


   RewriteEngine On

   RewriteRule ^(.*)$ public/$1 [L]

Better option (recommended for production environments), is to set you document root for apache (xampp) to the public folder, and not the laravel folder.

Source: https://coderwall.com/p/erbaig Source2: Personal Experience

Hi! on Xamp I'm using virtual host and on my shared host I did it like this : [http://driesvints.com/blog/laravel-4-on-a-shared-host]

IanSirkit replied 5 years ago

thepsion5 said:

Change your document root in your apache config from "your/path/to/laravel" to "your/path/to/laravel/public"

This is the best and most correct way to accomplish this. It is the recommended configuration from the Laraval install guide.

behnampmdg3 replied 5 years ago

Thanks guys,

This is great on local host. On my on line server I dont have accesst o apache config.

What should I do there?

Thanks

behnampmdg3 replied 5 years ago

So I decided to set up the virtual host. Things that I did:

/Applications/XAMPP/etc/httpd.conf

Include etc/extra/httpd-vhosts.conf    

/Applications/XAMPP/etc/extra/httpd-vhosts.conf


<VirtualHost *:80>ServerAdmin [email protected]
DocumentRoot "/Applications/XAMPP/htdocs/ben/public"
ServerName "Application/XAMPP/htdocs/ben"
ErrorLog "Application/XAMPP/htdocs/ben/error_logs_server"
</VirtualHost>

When I go to h t t p://localhost/ben I see the list of directories in that folder (including public).

I have also created the hosts file in etc and it contains


/Applications/XAMPP/htdocs/ben/public /Applications/XAMPP/htdocs/ben    

What would be the next step to fix this?

Thanks

rakeshksharma replied 4 years ago

Hi, I have tried this and i am also sharing way what i used for remove public from url Here

ErikEklund replied 4 years ago

If you can't set the root folder on a server, you can always do something like this:

  • copy the contents on "public" into the www-root folder
  • cope the rest of the laravel files (everything except the public folder) to anywhere on the hard drive (not inside the wwwroot)
  • change the path in index.php to point to the above folder to load bootstrap.php
  • change the paths in bootstrap/paths.php to point to the www-root

That way you can use the existing document root without getting a /public/ folder (or keeping your /app folder accessible from the web), and no need to change any server settings. Disclaimer: I didn't try it myself, but it should work :)

Hope that helps.

EhteshamMehmood replied 2 years ago

https://goo.gl/yIgUZW


Sign in to participate in this thread!



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