301重定向到完整路径 [英] 301 redirect to full path

查看:82
本文介绍了301重定向到完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多不正确的反向链接,这些链接指向:

I have a lot incorrect back links, the links are pointing to:

http://www.domain.com/tags/keyword

而正确的路径是

http://www.domain.com/tags/keyword/

有数百个......我怎么能 301 从错误的链接重定向到正确的链接?

there are hundreds of those...how could i 301 redirect from the wrong links to the correct links?

在此先感谢您

推荐答案

你可以试试这个代码:

RewriteBase /
RewriteRule ^tags/([^/]+)$ /tags/$1/ [L,R=301]

  • RewriteBase/ 告诉 apache 您的 URI 以 / 开头.如果您的站点位于子文件夹中,则应改为编写 RewriteBase/subfolder/.
  • ^tags/([^/]+)$:搜索以 tags/ 开头的 URI,后跟 [^/]+ 表示除 / 之外的任何字符.它周围的 ( ) 用于捕获它并在重定向中使用它.因此,我们捕获 URI 中 tags/.../ 之间不是 / 的任何字符.(^ 标记字符串的开始,$ 标记字符串的结尾)
  • /tags/$1/ 是重定向.$1 表示第一个捕获的元素(那个巫婆在 ( ) 之间).
  • [L,R=301] 向 apache 指示它应该停止处理其他规则并使用 301 标头代码重定向.
    • RewriteBase / tells apache that your URI starts by a /. If your site was in a subfolder you should write RewriteBase /subfolder/ instead.
    • ^tags/([^/]+)$: you search for an URI starting with tags/ followed by [^/]+ that means any characters except /. The ( ) around it are there to capture it and use it in the redirection. So we capture any characters that are not / between tags/.../ in the URI. (^ marks the start of the string while $ marks the end)
    • /tags/$1/ is the redirection. $1 means the first previous captured element (the one witch was between ( )).
    • [L,R=301] indicates to apache that it should stop process other rules and redirect with a 301 header code.
    • 这篇关于301重定向到完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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