我的网站有自己的主页和domain.com/blog/下的博客。在向浏览器发送301时,将domain.com/blog/请求发送到domain.com/的正确方法是什么,以便搜索引擎知道URL已移动?
这就是我所拥有的,但根本不起作用。
RewriteEngine on
RewriteCond %{http_host} ^domain.com/blog/ [nc]
RewriteRule ^/blog/$ http://www.domain.com/$1 [r=301,nc]
我已将domain.com替换为我的实际域名。
提前致谢!
答案 0 :(得分:1)
我认为您不需要RewriteRule中的$ 1,因为您要将来自domain.com/blog的用户重定向到domain.com。此外,1美元不能替代任何东西,因为你的正则表达式中没有使用任何括号。
修改强>
这应该适合你。
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com/blog/$ [NC]
RewriteRule ^/blog/$ http://www.domain.com [R=301,L]
答案 1 :(得分:0)
你忘了逃避第一行的句号。
==新代码==
RewriteEngine on
RewriteCond %{http_host} ^www\.domain\.com/blog/ [nc]
RewriteRule ^/blog/$ http://www.domain.com/$1 [r=301,nc]