2

私の web.xml ファイルでは、次のように構成しました。

<welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
</welcome-file-list>

つまり、 URL を入力するwww.domain.comと、index.xhtmlファイルがレンダリングに使用されます。しかし、入力www.domain.com/index.xhtmlすると、結果は同じです。それは複製コンテンツと呼ばれますか?これは私のプロジェクトでは問題ありませんが、SEO にとっては大きな問題です。転送を実行させる代わりに、www.domain.com/index.xhtmlURL を入力するときにページにリダイレクトするにはどうすればよいですか?www.domain.com

4

2 に答える 2

2

同じドメインにまったく同じ応答を返す別の URL がある場合、その URL は重複コンテンツとしてマークされます。はい、SEOが重要な場合は、間違いなくこれについて心配する必要があります.

これを修正する最も簡単な方法は、 の先頭にいわゆる正規 URL を提供することですindex.xhtml。これは、好みの URL を表す必要があります。これは、特定のケースでは明らかにファイル名を持つものです。

<link rel="canonical" href="http://www.domain.com/index.xhtml" />

このように、http://www.domain.comは として索引付けされhttp://www.domain.com/index.xhtmlます。コンテンツが重複することはもうありません。ただし、これによってエンドユーザーが別の URL をブックマーク/共有できなくなるわけではありません。

もう 1 つの方法は、設定した URL への HTTP 301 リダイレクトを構成することです。302 リダイレクトの発信元は引き続き検索ボットによってインデックス化されますが、301 リダイレクトの発信元ではなく、ターゲット ページのみがインデックス化されることを理解することは非常に重要です。でデフォルトで使用される 302 を使用するHttpServletResponse#sendRedirect()と、両方の URL がまだインデックス化されているため、コンテンツが重複することになります。

このようなフィルターのキックオフの例を次に示します。/index.xhtmlURI が目的のパスと一致しない場合は、マップして 301 リダイレクトを実行するだけです。

@WebFilter(urlPatterns = IndexFilter.PATH)
public class IndexFilter implements Filter {

    public static final String PATH = "/index.xhtml";

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
        String uri = request.getContextPath() + PATH;

        if (!request.getRequestURI().equals(uri)) {
            response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); // 301
            response.setHeader("Location", uri);
            response.setHeader("Connection", "close");
        } else {
            chain.doFilter(req, res);
        }
    }

    // init() and destroy() can be NOOP.
}
于 2013-11-25T11:16:22.447 に答える
0

重複するコンテンツを削除するには、URL パターンを使用してフィルターを設計します/*。ルート ドメインのユーザーの場合は、index.xhtmlURL にリダイレクトします。

@WebFilter(filterName = "IndexFilter", urlPatterns = {"/*"})
public class IndexFilter implements Filter {

    public void doFilter(ServletRequest req, ServletResponse resp,
        FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) resp;
    String requestURL = request.getRequestURI().toString();
    if (request.getServletPath().equals("/index.xhtml") &&
                !requestURL.contains("index.xhtml")) {
        response.sendRedirect("http://" + req.getServerName() + ":"
                + request.getServerPort() + request.getContextPath()
                +"/index.xhtml");
    } else {
        chain.doFilter(req, resp);
    }
}
 }
于 2013-11-24T17:07:38.007 に答える