웹어플리케이션서버
[NGINX] rewirte, redirect 주소변환 설정
미랭군
2021. 11. 5. 14:43
^/(정규식1)(정규식2)$
$1: 정규식1
$2: 정규식2
정규식 순서에 따라 순차적으로 매칭되는 변수 $숫자
# domain.com 으로 접속 시 newdomain.com 으로 리다이렉토
server {
server_name domain.com;
return 301 http://www.newdomain.com$request_uri;
}
# domain.com/change/view.php?no=1000 으로 접속 시 domain.com/changed/article.php?art_no=1000 으로 변환
server {
server_name domain.com;
location ~* ^/change/(.*)$ {
rewrite ^/change/(.*)$ http://domain.com/changed/$1 permanent;
break;
}
# domain.com/~~~ 으로 접속 시 newdomain.com/~~~ 으로 변환
server {
server_name domain.com;
location ~* ^(.*)$ {
rewrite ^(.*)$ http://www.newdomain.com$1 permanent;
break;
}
# domain.com/aaa.html 혹은 domain.com/bbb.html 으로 접속 시 domain.com/chage.html 으로 변환
server {
server_name domain.com;
location ~* ^(.*)$ {
rewrite ^/aaa.html$ /chage.html permanent;
rewrite ^/bbb.html$ /chage.html permanent;
break;
}