我已使用标准过程将SSL配置到运行在Tomcat上的应用程序中 . 我修改了server.xml文件和web.xml,以在每个请求中强制使用https . 我应该做两件事之一 .

1)正在发生的重定向是302重定向 . 如何将其作为301重定向?此302重定向不允许Google漫游器抓取我的网站

要么

2)使用一种机制,其中我需要的URL是http,从https重定向到http . 我知道一旦重定向到http,Tomcat就无法自动从https重定向到http . 我在web.xml中添加了以下条目,以便为我需要的URL启用http访问

<security-constraint>
    <web-resource-collection>
        <web-resource-name>SecureConnection</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>UnsecureConnection</web-resource-name>        
        <url-pattern>/Market/browseMarket.htm</url-pattern>
    </web-resource-collection>    
    <user-data-constraint>
        <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>   
</security-constraint>

但是,一旦使用第一个块将Tomcat重定向到https,即使第二个块存在,也无法重定向回http .

我在一些文章中读到了在应用程序中使用URLRedirectFilter来实现 . 为此,我在web.xml中添加了以下内容

<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

我已将urlrewrite.xml放在WEB-INF下,其内容为:

<urlrewrite>
   <rule>  
          <from>Market/browseMarket.htm</from>  
          <to>http://%{server-name}%{request-uri}</to>  
   </rule>  
</urlrewrite>

但是,这似乎不起作用,我仍然在该页面上使用https .

有人可以通过解决方案帮我解决上述问题之一吗?