Forum Moderators: rogerd & travelin cat

Message Too Old, No Replies

Moving directories and 301

         

Shimrit

8:22 am on May 17, 2016 (gmt 0)

10+ Year Member



I had my WP installed in the /blog directory and recently decided the rest of the site was no longer useful so moved it to the root directory. Don't think I can add links here, but I used the method described in Ask WP Girl ("move wordpress from subdirectory to root directory"). Namely changing site URL, changing this in the index.php:

"Example: if your WordPress installation folder is ‘mywp’, you would change:

require( dirname( __FILE__ ) . '/wp-blog-header.php' );

to

require( dirname( __FILE__ ) . '/mywp/wp-blog-header.php' );"

and redoing permalinks.

I copied the index.php over, rather than moved it, so there was one in the /blog directory and an identical one in the root directory.


It was nice and quick and all, but it made the /blog url 404, which is really not that I want, as most of the juice was coming in via there. So first I did:

redirect permanent /blog http://www.example.com

which of course then meant I could not access the wp-admin page which now also redirected to the www.example.com.
So I deleted that and did a redirect of /blog/index.php instead.

Now it all works fine, I can access the wp-admin page and the /blog redirects to the main homepage.

Just checking to see if that's correct SEO-wise and will pass the right juice onto my new location. The advice I originally followed is obviously not very SEO friendly!

Thanks :)

S

Andy Langton

1:23 pm on May 17, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The method you've described is rather patchy, unfortunately.

You should either:

- Change the URL in the site settings, and then physically move all the Wordpress files to root
- Just rewrite the requests to the blog directory with mod_rewrite (no moving necessary)

Then you can redirect any request for /blog without blocking access to the admin pages (or potentially breaking anything else).

If you don't want to move anything else now, use mod_rewrite for your redirects and add exceptions for admin pages, e.g. something like this:


RewriteCond %{REQUEST_URI} !wp-admin
RewriteRule ^blog/(.*) /$1 [R=301,L]


If you put back your old files, to rewrite requests for root the blog, use something like this (code is from [codex.wordpress.org...]


RewriteCond %{REQUEST_URI} !^blog
RewriteRule ^(.*)$ /blog/$1 [L]


You keep everything in the /blog directory, but users browse from the root.

Your redirects will send everything to the root, incidentally, so blog/post will go to the homepage - this will lose link value and Google will complain about soft 404s. Mod_rewrite redirects (as per first example above) are the way to fix this (RewriteRule ^blog/(.*) /$1 [R=301,L]).