2017-10-17 6 views
0

내가 이름을 변경 한 server.php 파일을 작동하지 않는 공공 형태의 URL을 제거하고laravel 5.4 index.php를 제대로

<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은이 URL없이 작동하고, 지금은 잘 작동 다음과 같이 htaccess로 코드를 추가하지만,

asset() 
public_path() 

기능이 제대로 작동하지 않습니다. css, js, 이미지가 제대로 호출되지 않습니다.

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

위의 코드는 모두 작동하지 않습니다. 이전에는 제대로 작동했습니다. 정상적으로 작동하는 것보다 제대로 추가 할 수는 있지만 올바르지 않은 방법입니다.

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

이 기능에 전역으로 공개 기능을 추가하려면 어떻게해야합니까?

또한이 참조를 사용하여 URL을 제거하려고했지만 작동하지 않습니다. How can I remove “public/index.php” in the url generated laravel?

+0

공유 호스트 계정입니까, 아니면 로컬 호스트입니까? – Michel

+0

공유 호스팅을 사용하고 있기 때문에이 작업을하고 있다고 생각합니다. 그렇지 않으면 Laravel 앱의 폴더에서 호스트의 루트 폴더를 '/ public'으로 설정해야합니다. 하지만 공유 호스팅을 사용중인 경우 공용 폴더에 대한 심볼릭 링크가 아닌 다음과 같은 이유 만 있으면됩니다.'ln -s/laravel-app/public/public_html' – gmask

답변

0

나는 이것을 해결하기 위해 세 가지를합니다.

나는 내 프로젝트의 루트 폴더

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

htaccess 파일을 넣어 그리고 내 공용 폴더에서이 .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> 

project-folder/public

나의 가상 호스트 설정을 정의한다
<VirtualHost *:80> 
    ServerName example.com 
    DocumentRoot "/path/projectfolder/public" 
    <Directory "/path/projectfolder/public"> 
     Options +Indexes +Includes +FollowSymLinks +MultiViews 
     AllowOverride All 
     Require All 
    </Directory> 
</VirtualHost> 

이 문제가 해결되었습니다.