Assuming you have already moved your site from the /blog
subdirectory to the document root and changed the URL structure within WordPress itself, so the /blog
subdirectory is not included in all your internal links, then you can either do a simple redirect (using mod_rewrite) in the /blog/.htaccess
file (preferable):
RewriteEngine On
RewriteRule (.*) /$1 [R=302,L]
This will redirect a URL of the form /blog/foo
to /foo
, since the captured backreference ($1
) does not contain the directory-prefix when used in a directory context.
Alternatively, if you want to delete the /blog
subdirectory altogether then you can do something like the following at the top of the root .htaccess
file, before the WordPress front-controller:
RewriteRule ^blog/(.*) /$1 [R=302,L]
Note that these are currently 302 temporary redirects. Only change to 301 permanent redirects when you are sure they are working OK.