Proper way to 301 redirect with htaccess
I have a site of mine that has its own homepage and a blog under domain.com/blog/. What 开发者_JS百科is the proper way of me sending the domain.com/blog/ requests to domain.com/ while sending a 301 to the browser so that search engines know that the URL has moved?
This is what I have, but not working at all.
RewriteEngine on
RewriteCond %{http_host} ^domain.com/blog/ [nc]
RewriteRule ^/blog/$ http://www.domain.com/$1 [r=301,nc]
I have replaced the domain.com to my actual domain.
Thanks in advance!
I don't think you need $1 in RewriteRule since you want to redirect users coming from domain.com/blog to domain.com. Besides, your $1 doesn't substitute anything because you don't use any parentheses in your regex.
EDIT:
This should work for you.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com/blog/$ [NC]
RewriteRule ^/blog/$ http://www.domain.com [R=301,L]
You forgot to escape the periods in the first line.
==NEW CODE==
RewriteEngine on
RewriteCond %{http_host} ^www\.domain\.com/blog/ [nc]
RewriteRule ^/blog/$ http://www.domain.com/$1 [r=301,nc]
精彩评论