apache/tomcat服务器下配置https
举例说明:
# http-->https
RewriteCond %{SERVER_PORT} !^443$
RewriteCond%{REQUEST_URI}%{QUERY_STRING}^(/user.php?act=login|/user.php?act=register|/user.php? act=profile)$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
当访问www.xxxx.cn/user.php?act=login的时候,.htaccess文件先判断一下端口号是否不是443(RewriteCond % {SERVER_PORT} !^443$),再判断URL的路径中是否包含了user.php?act=login(RewriteCond% {REQUEST_URI}%{QUERY_STRING}^(/user.php?act=login|/user.php?act=register|/user.php?
act=profile)$),如果两个条件都符合,则执行下一步,跳转到 https://www.xxxx.cn/user.phpact=login (RewriteRule ^.*$ https://% {SERVER_NAME}%{REQUEST_URI}
[L,R])。(https-->http也是同理)
>http)。
<span style="font-size:18px;"> <security-constraint>
<web-resource-collection >
<web-resource-name >SSL</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection> <user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint></span>
第二种:1、下载urlrewritefilter.jar(点击下载),导入项目中。
<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>
3、在项目目录下创建urlrewrite.xml文件,内容如下。
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.0//EN"
"http://tuckey.org/res/dtds/urlrewrite3.0.dtd">
<urlrewrite>
<rule>
<condition type="scheme" operator="notequal">https</condition>
<condition name="host" operator="equal">localhost</condition>
<condition type="port" name="port" operator="equal">8888</condition>
<condition type="query-string" operator="equal">^model=.*&ObjectName=.*$</condition>
<from>^(/servlet/MobileServlet)$</from>
<to type="permanent-redirect">https://%{host}:8443%{request-uri}?%{query-string}</to>
</rule>
</urlrewrite>