【问题标题】:is there a way to implement the X-Robots-Tag instruction with tomcat?有没有办法用 tomcat 实现 X-Robots-Tag 指令?
【发布时间】:2019-10-25 13:13:22
【问题描述】:

我想将X-Robots-Tag noindex, nofollow 添加到站点的所有 .PDF 文件的 HTTP 响应中,以避免 Google 搜索引擎引用这些文档。

这适用于 Heroku 上带有 Spring boot 2.1 的 Tomcat 8 服务器。过去,我在 Apache Server 上尝试过,noindexnofollow 运行良好。

<Files ~ "\.pdf$">
  Header set X-Robots-Tag "noindex, nofollow"
</Files>

【问题讨论】:

    标签: java spring-boot tomcat heroku x-robots-tag


    【解决方案1】:

    您可以创建一个 servlet 过滤器来为您执行此操作。

    @WebFilter(urlPatterns = {"*.pdf"})
    public class PdfFilter implements Filter {
    
        @Override 
        public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain) throws IOException, ServletException {
    
             HttpServletResponse httpServletResponse = (HttpServletResponse)response;
             httpServletResponse.addHeader("X-Robots-Tag", ""noindex, nofollow");
    
             chain.doFilter(request, response);
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-17
      • 2020-11-24
      • 2017-10-05
      • 1970-01-01
      • 1970-01-01
      • 2020-06-02
      • 1970-01-01
      • 2019-04-26
      相关资源
      最近更新 更多