PHP/Laravel

Laravel Routing이 Apache Routing 보다 우선순위가 낮을 때

DSeung 2023. 6. 14. 13:42

Larvel로 만든 프로젝트를 배포할 때 "/"로 시작하는 라우팅은 정상 작동하지만 그 외의 주소로 이동 시

라라벨의 404가 아닌 아파치의 기본 404가 나올 때 적용할 수 있는 방법입니다.

 

원인은 간단하게 아파치 설정에서 .haccess 파일로 오버라이딩 여부를 허용 안 해서 그렇습니다.

 

우선 아파치의 httpd.conf 파일을 찾은 후 열어보시면

아래와 같은 형태의 태그로 감싸진 부분을 찾을 수 있습니다, 저 같은 경우 /var/www/html로 사이트를 배포하기에 아래와 같은 코드가 보입니다.

# Further relax access to the default document root:
<Directory "/var/www/html">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

여기서 안되시는 분들은 AllowOverride 값이 None으로 되어있을 것 입니다.

이 값을 All로 바꿔줘야 .htaccess 파일을 읽고 라라벨 라우팅이 정상적으로 작동됩니다.

 

반응형