【问题标题】:How do we redirect all requests to one domain to a section of another domain?我们如何将所有对一个域的请求重定向到另一个域的一部分?
【发布时间】:2011-02-15 10:08:05
【问题描述】:

我们有两个域,example.comexample.net· 我们希望对example.net 的每个请求都重定向到example.com/example_section/index.jsp。我们怎样才能做到这一点?

【问题讨论】:

  • 请详细说明您的需求。如果您只是通过 onclick 事件在 js 中进行重定向。 onclick = 'window.location.href="site.com/sectionxxx/index.jsp"' 这样就可以使用了。

标签: jsp url redirect


【解决方案1】:

在服务器上的 .htaccess 文件中

Redirect permanent http://www.example.net/index.jsp http://www.example.com/example_section/index.jsp.

或者你可以在http://www.example.net/index.jsp页面创建页面并添加

<% 
    String redirectURL = "http://www.example.com/example_section/index.jsp"; 
    response.sendRedirect(redirectURL);
%> 

或者你可以在同一页上写

<jsp: forward page="http://www.example.com/example_section/index.jsp"/>

这将转发页面。

【讨论】:

  • .htaccess 文件仅在您的 servletcontainer 以 Apache HTTPD 为前端时才有效(因为 .htaccess 文件是 Apache HTTPD 特定的,不适用于 Tomcat 等)。 scriptlet 方式将起作用,但Filter 之类的this one 是首选方式。 jsp:forward 完全是服务器端的,不会反映浏览器地址栏中的 URL 变化。
猜你喜欢
  • 2012-10-19
  • 2016-02-09
  • 2013-06-24
  • 2014-08-28
  • 2013-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多