Bor*_*nov 5 dns redirect jetty
我无法将我的非www域版本重定向到www MovedContextHandler,它没有主机重定向到.
双方www.example.com并example.com指向我的Web服务器的IP.当有人试图打开时,example.com他仍然能够以这种方式访问我的网站.我想让他的浏览器接收HTTP 301重定向www.example.com.对搜索排名来说很重要,因为搜索引擎必须知道example.com并且www.example.com是同一个.
作为奖励,当有人试图访问example.com/somepath/somepage.html我想要HTTP 301重定向www.example.com/somepath/somepage.html
我该如何处理?我是否需要编写自己的处理程序或者是否有更简单的方法?
要避免重定向循环,您必须定义此规则的虚拟主机.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.server.handler.MovedContextHandler">
<Set name="contextPath">/</Set>
<Set name="newContextURL">http://www.example.com</Set>
<Set name="permanent">true</Set>
<Set name="discardPathInfo">false</Set>
<Set name="discardQuery">false</Set>
<Set name="virtualHosts">
<Array type="String">
<Item>example.com</Item>
</Array>
</Set>
</Configure>
Run Code Online (Sandbox Code Playgroud)
我通过查看源码找到了解决方案。您只需在 MovedContextHandler 内重定向到的 URL 中指定架构即可。像这样: http: //www.somedomain.com 如果您只使用 www.somedomain.com,则重定向将无法正常工作。
这是我的redirector.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.server.handler.MovedContextHandler">
<Set name="contextPath">/</Set>
<Set name="newContextURL">http://www.somedomain.com</Set>
<Set name="permanent">true</Set>
<Set name="discardPathInfo">false</Set>
<Set name="discardQuery">false</Set>
</Configure>
Run Code Online (Sandbox Code Playgroud)