How to get absolute url as href/src value using Thymeleaf and Urlrewritefilter

坚强是说给别人听的谎言 提交于 2019-12-12 03:02:18

问题


I'm using Thymeleaf templating engine with Spring boot for developing my web application. For rewriting url, I'm using UrlRewriteFilter library.

My problem is that I couldn't able to rewrite url to a absolute url. For example, if script src value is configured in html like below

<script th:src="@{/js/jquery.js}"></script>

and rules defined in urlrewrite.xml as

<urlrewrite>
        <outbound-rule>
            <from>/js/jquery.js</from>
            <to>https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-rc1/jquery.js</to>
        </outbound-rule>
</urlrewrite>

The expected output is

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-rc1/jquery.js"></script>

But it is generating as

<script src="/myapphttps://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-rc1/jquery.js"></script>

where /myapp is context root. How to get rid of context root and get only absolute url which I configured.

来源:https://stackoverflow.com/questions/37725943/how-to-get-absolute-url-as-href-src-value-using-thymeleaf-and-urlrewritefilter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!