没有索引URL分隔符符号通过htaccess

时间:2016-11-14 11:53:21

标签: .htaccess url symbols

我有一个基本结构的WordPress网站:URL关键字分隔符符号是/。问题是我创建的页面可以使用URL中的/或+符号进行访问。

我的意思是,我可以在mydomain.com/example-page/和mydomain.com/example+page/访问同一页面。我知道这对SEO有害所以我提出一个问题:是否可以通过htaccess将noindex nofollow命令设置为在URL中使用+符号分隔符的所有页面?

如果您有更好的解决方案,我将不胜感激!

1 个答案:

答案 0 :(得分:0)

您可以使用(在实际的htaccess代码之前):

RewriteEngine on
# executes repeatedly as long as there are more than 1 spaces in URI
RewriteRule "^(\S*)\s+(\S*\s.*)$" /$1-$2 [L,NE]
# executes when there is exactly 1 space in URI
RewriteRule "^(\S*)\s(\S*)$" /$1-$2 [L,R=302,NE]

谁将版本示例+页面重定向到example-page