简体   繁体   中英

laravel 5.4 removing public form url not working properly

I have renamed server.php file to index.php and added .htaccess code as follows

<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]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

url is working fine now, it is working without url, but

asset()
public_path()

function are not working properly. css, js , images are not called properly.

{{ asset('assets/css/custom.css') }}

Above code to all custom.css is not working, it was working properly before. If I add public than it work properly, but that is not correct way.

{{ asset('public/assets/css/custom.css') }}

Let me know how can I add public globally to these function.

I also tried to remove url using this reference but it doesn't work. How can I remove “public/index.php” in the url generated laravel?

I do three things to solve this.

I put this htaccess file in my project root folder

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

And this .htaccess configuration in my public folder, that is, project-folder/public

<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>

then define my virtual host configuration as

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot "/path/projectfolder/public"
    <Directory  "/path/projectfolder/public">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require All
    </Directory>
</VirtualHost> 

This solves the problem for me

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