
nginx에 다음 줄이 있습니다.
try_files $uri $uri/ /index.html;
내가 아는 한, 찾을 수 없는 파일에 대한 모든 쿼리를 다시 작성합니다 index.html
. 즉, Google 크롤링을 망치는 동일한 결과를 남깁니다 index.html?foo=bar
.idontexist.html?foo=bar
어떻게 다시 쓰지 않고 기본 URL로 리디렉션할 수 있나요?
완벽한 솔루션은 index.html
. 따라서 http://domain.com/idontexist.html?foo=bar
301을 사용하여 리디렉션합니다.http://domain.com/?foo=bar
답변1
location / {
try_files $uri $uri/ @to_home;
...
}
location @to_home {
return 301 /$is_args$args;
}
답변2
위의 VBart 코드 조각을 단축했습니다. 다음과 같이 작동합니다.
try_files $uri $uri/ / =301;