首页 > 解决方案 > .htaccess 问题重定向 301 -

问题描述

我们已经重组了我们的网站并尝试实施 Redirect 301,但无济于事。看起来很简单,但是页面不会重定向,当我们验证示例 URL 时,状态 200 仍然显示在原始页面上。

这是我们正在使用的代码:

AddHandler server-parsed .htm .html
DirectoryIndex index.jsp index.htm /index.jsp

    RewriteEngine On 
    # Redirect to preferred www example 
    RewriteCond %{HTTP_HOST} ^example\.com 
    RewriteRule (.*) https://example.com/$1 [R=301,L] 

    Redirect 301 /products/manufacturer_1.jsp https://www.example.com/brands/manufacturer_1.jsp

HTTP 到 HTTPS 重写工作正常,但重定向 301 不能。没有其他重写或重定向,所以不应该有任何冲突。

任何建议都会有所帮助,并提前感谢您的帮助。

最好的,马修

标签: apache.htaccessredirect

解决方案


因为我们使用的是 JSP 页面。.htaccess 中的重定向 301 从未被处理。因此,我们必须在我们的页面上嵌入以下代码:

<%
response.setStatus(301);
response.setHeader( "Location", modelUrlString );
response.setHeader( "Connection", "close" );
%>

推荐阅读