url路徑去掉兩個opencms
采用剛剛的方法安裝OpenCMS之後,站點url中會存在兩個opencms,造成訪問url路徑過長,下面講解一種去掉兩個opencms的方法。
1.去掉第一個opencms
安裝時采用ROOT安裝,即把opencms.war改名為ROOT.war放到webapp下進行安裝,這樣第一個/opencms就去掉了,不用配置其他任何參數。
此時的安裝路徑:http://localhost:8080/ setup
2.去掉第二個opencms
使用urlrewrite模塊實現,步驟如下:
(1)下載urlrewrite-3.2.0.jar包,把jar包放到tomcat根目錄/webapps/ROOT/WEB-INF/lib目錄下;
(2)在tomcat根目錄/webapps/ROOT/WEB-INF/目錄下新建一個urlrewrite.xml文件,代碼清單參見1;
代碼清單1 tomcat根目錄/webapps/ROOT/WEB-INF/urlrewrite.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
"http://tuckey.org/res/dtds/urlrewrite3.2.dtd">
<!--
Configuration file for UrlRewriteFilter
http://tuckey.org/urlrewrite/
-->
<urlrewrite>
<rule>
<from>^/tc-mgr/(.*)$</from>
<to>/tc-mgr/$1</to>
</rule>
<rule>
<condition type="request-uri" operator="notequal">^/export/.*$</condition>
<condition type="request-uri" operator="notequal">^/resources/.*$</condition>
<condition type="request-uri" operator="notequal">^/opencms-errorhandler/.*$</condition>
<condition type="request-uri" operator="notequal">^/webdav/.*$</condition>
<condition type="request-uri" operator="notequal">^/opencms/.*$</condition>
<condition type="request-uri" operator="notequal">^/setup/.*$</condition>
<from>^/(.*)$</from>
<to>/opencms/$1</to>
</rule>
</urlrewrite>
(3)創建完urlrewrite.xml文件後,打開tomcat根目錄/webapps/ROOT/WEB-INF/web.xml文件,找到以下代碼片段:
<listener>
<listener-class>org.opencms.main.OpenCmsListener</listener-class>
</listener>
然後在其後面添加過濾器配置代碼,參見代碼清單2;
代碼清單2 tomcat根目錄/webapps/ROOT/WEB-INF/web.xml:新增過濾器配置
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>confReloadCheckInterval</param-name>
<param-value>-1</param-value>
</init-param>
<init-param>
<param-name>logLevel</param-name>
<param-value>ERROR</param-value>
</init-param>
<init-param>
<param-name>statusEnabled</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>statusPath</param-name>
<param-value>/status</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
(4)接下來修改tomcat根目錄/webapps/ROOT/WEB-INF/config/opencms-importexport.xml,找到如下的配置代碼片段:<vfs-prefix>${CONTEXT_NAME}/${SERVLET_NAME}</vfs-prefix>,刪除其中的/${SERVLET_NAME},即最終修改為:
<vfs-prefix>${CONTEXT_NAME}</vfs-prefix>
至此,第二個/opencms去除成功,記得修改完畢後重啟Tomcat服務器,首頁地址如下:
http://localhost:8080/ index.html
OpenCMS後臺工作區的登錄頁面鏈接地址如下:
http://localhost:8080/ system/login/
url路徑去掉兩個opencms