programing tip

Tomcat 기본 URL 리디렉션

itbloger 2020. 10. 29. 07:53
반응형

Tomcat 기본 URL 리디렉션


바람둥이를 사용하여, 어떻게에 대한 요청을받을 수 있나요 http://www.mydomain.com 로 리디렉션 http://www.mydomain.com/somethingelse/index.jsp를 ? 나는 http://mydomain.com 에서 표시 할 index.html을 얻지 못했습니다 .


웹앱 WAR의 이름을 "ROOT.war"로 지정하거나 "ROOT"폴더를 포함합니다.


다음을 수행 할 수 있습니다. Tomcat 설치가 기본값이고 변경을 수행하지 않은 경우 기본 전쟁은 ROOT.war. 따라서를 호출 할 때마다 기본 WAR 파일 http://yourserver.example.com/index.html또는 index.jsp호출 합니다. webapp/ROOT요청을로 리디렉션하려면 폴더 에서 다음과 같이 변경하십시오 http://yourserver.example.com/somewhere/else.

  1. 열기 webapp/ROOT/WEB-INF/web.xml, 경로 어떤 서블릿 매핑을 제거 /index.html하거나 /index.jsp, 저장.

  2. 있는 webapp/ROOT/index.html경우 제거하십시오 .

  3. 다음 내용으로 파일 webapp/ROOT/index.jsp만듭니다 .

    <% response.sendRedirect("/some/where"); %>
    

    또는 다른 서버로 연결하려는 경우

    <% response.sendRedirect("http://otherserver.example.com/some/where"); %>
    

그게 다야.


본질적으로 Apache의 mod_rewrite의 Java 기반 구현 인 UrlRewriteFilter살펴보십시오 .

ROOTTomcat 폴더 아래의 폴더에 압축을 풀어야 webapps합니다. 그런 다음 WEB-INF/urlrewrite.xml구성 파일 내의 다른 컨텍스트에 대한 리디렉션을 구성 할 수 있습니다 .


테스트 및 작업 절차 :

파일 경로로 이동 ..\apache-tomcat-7.0.x\webapps\ROOT\index.jsp

전체 내용을 제거하거나 index.jsp 맨 위에 아래 코드 줄을 선언하십시오.

<% response.sendRedirect("http://yourRedirectionURL"); %>

jsp 파일에서 위의 줄을 <%로 시작하고 %>로 끝나야합니다.


제가 한:

ROOT / index.jsp 안에 다음 줄을 추가했습니다.

 <meta http-equiv="refresh" content="0;url=/somethingelse/index.jsp"/>

Tomcat 8에서는 rewrite-valve를 사용할 수도 있습니다.

RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^/(.*)$         /somethingelse/index.jsp

재 작성 밸브를 설정하려면 여기를 참조하십시오.

http://tonyjunkes.com/blog/a-brief-look-at-the-rewrite-valve-in-tomcat-8/

참고 URL : https://stackoverflow.com/questions/1363605/tomcat-base-url-redirection

반응형