Contacta con nosotros
contacto@flabo.es

Ajustar urlrewrite en Liferay

Liferay utiliza la librería urlrewrite de tuckey para manejar redirecciones de igual manera que el conocido mod_rewrite de apache. Esta librería nos permite tener un sistema de gestión de redirecciones en la primera fase de procesado de las peticiones, por lo que es muy util por ejemplo para mantener el SEO de un portal o la compatibilidad con otras aplicaciones.

Site oficial : http://tuckey.org/urlrewrite/

El caso es que la forma de utilizarlo en Liferay es mediante un filtro definido en el fichero liferay-web.xml con la siguiente definición:

	<filter>
		<filter-name>URL Rewrite Filter</filter-name>
		<filter-class>com.liferay.portal.servlet.filters.urlrewrite.UrlRewriteFilter</filter-class>
		<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>url-regex-ignore-pattern</param-name>
			<param-value>(^/combo/)|(^/html/.+\.(css|gif|html|ico|jpg|js|png)(\?.*)?$)</param-value>
		</init-param>
	</filter>

Lo que propongo es ajustar el patron de urls a ignorar para evitar que se procese el filtro con todas y cada una de las peticiones realizadas a nuestro portal, normalmente solo se van a redirigir páginas.

Si activamos los logs del filtro podemos ver como por cada petición se van chequeando todas las reglas definidas en el urlrewrite.xml

INFORMACIÓN: org.tuckey.web.filters.urlrewrite.UrlRewriter DEBUG: url /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 0 run called with /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase TRACE: no match on "from" for ^/api/webdav(.{0,2000}) and /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 1 run called with /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase TRACE: no match on "from" for ^/(.{1,1000}/)?blog/blogs/rss(.{0,1000}) and /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 2 run called with /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase TRACE: no match on "from" for ^/(.{1,1000}/)?-/blogs/rss\?&(.{0,1000}) and /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 3 run called with /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase TRACE: no match on "from" for ^/c/journal/view_article_content\?groupId=14&articleId=155291$ and /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 4 run called with /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase TRACE: no match on "from" for ^/(.{1,1000}/)?tunnel-web(.{0,1000}) and /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 5 run called with /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase TRACE: no match on "from" for ^/web/guest/community/forums/message_boards(.{0,2000})$ and /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 6 run called with /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase TRACE: no match on "from" for ^/web/guest/home/journal/rss/14/news$ and /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 7 run called with /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase TRACE: no match on "from" for ^/web/guest/home/journal/rss/14/news$ and /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 8 run called with /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase TRACE: no match on "from" for ^/web/guest/home/journal/rss/14/news$ and /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 9 run called with /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase TRACE: no match on "from" for ^/web/guest/home/journal/rss/14/news$ and /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 10 run called with /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase TRACE: no match on "from" for ^/web/guest/home/journal/rss/14/news$ and /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 11 run called with /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase TRACE: no match on "from" for ^/web/guest/home/journal/rss/14/news$ and /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 12 run called with /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase TRACE: no match on "from" for ^/web/guest/home/journal/rss/14/news$ and /web/guest/test?param=
INFORMACIÓN: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 13 run called with /web/guest/test?param=

Para evitar que ejecute para peticiones innecesarias podemos cambiar el patrón por lo siguiente:

<param-value>(^/combo/)|(^/image/)|(^/document/)|(^.*\.(css|gif|html|ico|jpg|js|png|woff|ttf|eot|bmp).*)|(^/html/.+\.(css|gif|html|ico|jpg|js|png)(\?.*)?$)</param-value>