2017-01-08 2 views
0

나는 그것이 example.com/u/User에서 현재의로, 루트 디렉토리에 사용자 프로필을 꿔, 나는 루트 사용자 디렉토리의 사용자 정의 URL?

그래서 내가 만든이 구성을 example.com/User을 꿔 :

location @extensionless-php { 
     rewrite ^(.*)$ $1.php last; 
    } 
    location @try-user { 
     rewrite ^(.*)$ /profile.php?user=$1; 
    } 

    location/{ 
       try_files $uri $uri.html $uri/ @extensionless-php @try-user; 
       # To do: try-page 
       index index.html index.htm index.php; 
       expires 1h; 
       rewrite ^/messages/(.*)$ /messaging.php?u=$1; 
    } 

해당 설정이있는 페이지로 이동할 때마다 @ try-user로 이동하고 사용자 이름 (example.com/Phil)을 입력하면 "사용자를 찾을 수 없음"이 표시됩니다.

아무도 도와 줄 수 있습니까?

+0

'try_files' 문에 두 개의 명명 된 위치를 사용할 수 없습니다. [이 문서] (http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files)를 참조하십시오. 달성하고자하는 URI는'/profile.php? user =/Phil' 또는'/profile.php? user = Phil'입니까? –

+0

/profile.php?user=Phil – Phil

답변

0

귀하의 try_files 문장은 최종 용어 만 명명 된 위치 일 수 있기 때문에 정확하지 않습니다. 자세한 내용은 this document을 참조하십시오.

nginx URI는 선두가 /으로 시작됩니다. 다시 작성하는 경우 사용자 이름을 캡처하려는 경우 앞에 /을 캡처하지 않아야합니다. 예를 들어

:

location @try-user { 
    rewrite ^/(.*)$ /profile.php?user=$1; 
} 
location/{ 
    try_files $uri $uri.html $uri/ @try-user; 
    ... 
} 

아무것도가 PHP 파일로 취급되는 반면 사용자 이름을 일치하는 패턴이 profile.php로 리디렉션되도록 두 개 이상의 rewrite 문를 원하는 및 주문을 할 수도 있습니다. 예 :

location @try-user { 
    rewrite ^/([^/]+)$ /profile.php?user=$1 last; 
    rewrite ^(.*)$ $1.php last; 
} 

자세한 내용은 this document을 참조하십시오.

+0

확장 기능이없는 PHP도이 기능과 함께 사용하고 싶습니다. 가능합니까? – Phil

+0

두 번째 예제에서이를 설명하려고했습니다. 분명히'/ foo '와 같은 URI는 사용자 이름으로 해석되지만'/ foo/bar'와 같은 URI는'/ foo/bar.php'로 리디렉션됩니다. –