0

I have read and tried different solutions to this problem including the ones from this post Laravel 5 – Remove Public from URL but It didn't work for me. I have a folder called 'abimswake' - the root folder. Every time i have to access my project I access through this url http://localhost:8080/abimswake/public/login After trying all the solutions from that post, my url changes to http://localhost:8080/public/public when i try to access the same URL

Then I also want to know how the url will look like without the public in it. Please someone help me. my .htaccess file is here

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

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

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

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Laravel's `public` folder should be the DocumentRoot of your server – brombeer Feb 21 '18 at 11:59
  • What do you mean by "how the url will look like without the public in it"? What about `http://localhost:8080/public` or `http://localhost:8080/`? – Nico Haase Jun 25 '19 at 09:21

1 Answers1

1

Update your web server's virtual host to point to abimswake/public and use the default Laravel .htaccess file in the public directory.

Default htaccess

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

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

Apache Virtual Host Example

<VirtualHost *:80>
  ServerName hostname-goes-here
  DocumentRoot "/path/to/abimswake/public"
  <Directory "/path/to/abimswake/public">
    AllowOverride all
  </Directory>
</VirtualHost>

Nginx Virtual Host Example

server {
    listen 80;

    root /path/to/abimswake/public;
    index index.php index.html index.htm;

    server_name hostname-goes-here;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

This would server from the public directory and using your hostname (you use localhost at the moment, I'd recommend creating a custom hostname). Combined with the default .htaccess, you should have no unwanted subdirectories in your URL.

HelloSpeakman
  • 810
  • 9
  • 22