301 redirect to full path

百般思念 提交于 2020-01-16 00:35:29

问题


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

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

while the correct path is

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

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

Thank you so much in advance


回答1:


You can try this code:

RewriteBase /
RewriteRule ^tags/([^/]+)$ /tags/$1/ [L,R=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.


来源:https://stackoverflow.com/questions/35033190/301-redirect-to-full-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!