How do I get the root index page to redirect to a subdirectory without affecting SEO?

How do I get the root index page to redirect to a subdirectory without affecting SEO? - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the How do I get the root index page to redirect to a subdirectory without affecting SEO? error on your web browser. Problem :


I am reviving/reorganising my personal WordPress blog.



It's using a URL that looks like this:



http://mydomain.com/blog



The webserver 301 redirects www.mydomain.com to mydomain.com.



I want to use the blog subdirectory because I plan to add other parts to the site, with the blog only being one part of the site.



However, at the moment there is nothing there but the blog, so I want to have the root index page redirect to the blog for the time being.



I have been using this on the root index.html page to do the redirect...



<meta http-equiv="REFRESH" content="0;url=./blog">



...but this seemed to have stopped the site being indexed by Google and Bing.



How do I do this without affecting SEO? Also, what URL should I put in the sitemap.xml?


Solution :

You could rewrite URLs internally in your root .htaccess file.



RewriteEngine On

#if request is mydomain.com/something OR
RewriteCond %HTTP_HOST ^mydomain.com$ [OR]

# or www.mydomain.com/something
RewriteCond %HTTP_HOST ^www.mydomain.com$

# but not mydomain.com/blog
RewriteCond %REQUEST_URI !^/blog/

#change it to mydomain.com/blog/something
RewriteRule (.*) /blog/$1 [R=301]


Or, if you want to apply a temporary solution till you develop the other parts of site, you could place an index.php in the root with this following code:



<?php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.mydomain.com/blog" );
?>


Benefits of this approach is that no present/possible messing up of URLS. And it is simpler than .htaccess approach. Also this will tell Google that this page moved permanently ( or temorary with 302) to this new location. (Although [R=301] in .htaccess would have done same thing.)



Here is a discussion about 301 & 302 redirects by Matt Cutts


We hope that this article has helped you resolve the seo, redirects, error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=