简体   繁体   中英

How do I by-pass the Public Folder in the url (Laravel 5.4)

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM