나는 다음과 같은 URL이 있습니다Nginx에 재 작성 규칙
mywebsite.com/template/product.html
을 나는
mywebsite.com/로 재 작성하려면 제품
location/{
alias /var/www/web/;
rewrite ^/(mywebsite.com/template/.*)\.html$ /$1 last;
}
나는 다음과 같은 URL이 있습니다Nginx에 재 작성 규칙
mywebsite.com/template/product.html
을 나는
mywebsite.com/로 재 작성하려면 제품
location/{
alias /var/www/web/;
rewrite ^/(mywebsite.com/template/.*)\.html$ /$1 last;
}
도메인을 일반 variabile로 처리 할 것인지 확실하지 않습니다.
어쨌든 mywebsite.com
에 대한 서버 conf를 설정하면이 구성이 사용자의 케이스에 맞아야합니다.
server {
error_log logs/mywebsite.com.log debug;
server_name mywebsite.com;
root /var/www/web/mywebsite.com;
# this directive handle the redirects from old name.html to new format
location /template/ {
rewrite ^/template/([^.]+)\.html$ /$1 redirect;
}
# given new new url format this directive match the name and
# read the file
location ~* ^/([^.]+)$ {
try_files /template/$1.html /template/notfound.html;
}
}
작성하신 정규식이 제품 이름과 일치하지 않습니다. 이제 그룹이 귀하의 요구 사항에 적합해야합니다. 브라우저 나 봇을 새 URL로 리디렉션하려고한다고 가정하기 때문에 다시 쓰기 플래그 last
을 redirect
에 수정했습니다.
작동하지만 표시가 404 없습니다. 여기서 문제는 무엇입니까? 아니, 방대한 호스팅이 아닙니다. ''http : // mywebsite.com/template/product.html'와 같이''http : // mywebsite.com/product /''에서 같은 페이지를 보길 원합니다. –
문제는 질문 '/ template/name.html'에서'/ name'으로 요청을 보내는 방법입니다. 새로운 URL 형식으로 html을 읽는 방법에 대해서는 의문의 여지가 없었습니다. 새로운 문제에 대한 해결책이 필요하다고 가정했다고 가정합니다. 어쨌든, 나는 나의 대답을 업데이트했다. – freedev
잘 모르겠습니다. http 요청과 관련하여 질문의 유스 케이스가 있습니다. 'http : // mywebsite.com/template/product.html' 요청을 모두'http : // mywebsite.com/product'로 리다이렉트 (302 또는 301)해야합니까? 다시 질문 태그에 아파치를 추가 한 이유는 무엇입니까? – freedev
나는 대부분의 아파치 사용자가 nginx에 대해 알고 있다고 생각했다. 예, 모든 요청을 "http : // mywebsite.com/product /"로 리디렉션하고 싶습니다. –
도메인을 일반 변수로 처리 하시겠습니까? 이것은 거대한 호스팅입니까? – freedev