3

I'm following the following Structure as I don't want to expose my code to the public.

The folder structure in my localhost is

tbt
    tbt/user/
    tbt/public_html/

where user contains all the folder of root without the public folder and public_html contains the public files.

And I have changed in below lines in public_html/index.php:

require __DIR__.'/../user/bootstrap/autoload.php';
$app = require_once __DIR__.'/../user/bootstrap/app.php';

But when i run the application,

I'm getting Url like localhost/tbt/user/xxxx But it should be localhost/tbt/xxx

I have followed this solution for solving the problem but couldn't solve it as My application is on Laravel 5. Anyone who can help me to find the solution please?

Community
  • 1
  • 1
User57
  • 2,453
  • 14
  • 36
  • 72
  • Try this : `require __DIR__.'/bootstrap/autoload.php'; $app = require_once __DIR__.'/bootstrap/app.php';` – long hoangvan Jun 24 '16 at 06:54
  • `Warning: require(C:\xampp\htdocs\public_html/bootstrap/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\public_html\index.php on line 27` Line 27 :` require __DIR__.'/bootstrap/autoload.php';` – User57 Jun 24 '16 at 08:39
  • look like your root forget `tbl`, try to add `/..` before `/bootstrap` – long hoangvan Jun 24 '16 at 09:20
  • Same Error I'm getting >> `Warning: require(C:\xampp\htdocs\public_html/../bootstrap/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\public_html\index.php on line 27` – User57 Jun 24 '16 at 12:27

3 Answers3

1

Process 1

  1. Rename the server.php in the your Laravel root folder to index.php
  2. copy the .htaccess file from /public directory to your Laravel root folder.

Process 2

  1. Follow process 1

  2. Update the .htaccess as below

.htaccess look like below

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]
abSiddique
  • 11,647
  • 3
  • 23
  • 30
  • My problem isn't about removing public from url actually I want to host my application from 'public_html' and facing difficulty with that! – User57 Jun 24 '16 at 12:29
1

You can setup a alias in your web server, pointing to your public folder. It's simple but works for me

https://httpd.apache.org/docs/2.4/urlmapping.html

Mahmood
  • 1,069
  • 9
  • 11
1

In the root directory of your Laravel project create a file with name .htacess and paste this code in it

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

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]

RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
Imad Ullah
  • 929
  • 9
  • 17