将Jet的非www版本的域名重定向到www [英] Redirect non www version of domain to www in Jetty

查看:116
本文介绍了将Jet的非www版本的域名重定向到www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用 MovedContextHandler 将我的非www域名版本重定向到www,没有主机重定向到。

I cannot redirect my non www domain version to www with MovedContextHandler, it does not have host to redirect to.

指向我的网络服务器IP的 www.example.com example.com 当有人试图打开 example.com ,他仍然可以访问我的网站。我希望他的浏览器接收HTTP 301重定向到 www.example.com 。搜索排名很重要,因为搜索引擎必须知道 example.com www.example.com 是一个和相同的。

Both www.example.com and example.com point to my web server IP. When someone tries to open example.com he is still able to access my site that way. I want for his browser to receive HTTP 301 redirection to www.example.com instead. It is important for search rankings, as search engines must know example.com and www.example.com are one and the same.

作为奖金,当有人试图访问 example.com/somepath/somepage.html 想要一个HTTP 301重定向到 www.example.com/somepath/somepage.html

As a bonus, when someone tries to access example.com/somepath/somepage.html I want a HTTP 301 redirection to www.example.com/somepath/somepage.html

如何继续那?我需要编写自己的处理程序,还是有更简单的方法?

How do I proceed with that? Do I need to write my own handler or is there an easier way?

推荐答案

我通过查看源代码找到了解决方案。您只需要在MovedContextHandler内重定向到的URL中指定模式。像这样: http://www.somedomain.com
如果你只做www.somedomain。 com,重定向将无法正常工作。

I found the solution by looking at the source. You just need to specify the schema in the URL you are redirecting to inside the MovedContextHandler. Like this: http://www.somedomain.com If you only do www.somedomain.com, the redirect won't work properly.

这是我的redirector.xml

This is my 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>

这篇关于将Jet的非www版本的域名重定向到www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆