I have a WordPress blog on pcelarstvopejcic.com/blog and a few pages that I would like to move to the domain document root, so that:
- pcelarstvopejcic.com/blog/contact becomes pcelarstvopejcic.com/contact
- pcelarstvopejcic.com/blog/shop becomes pcelarstvopejcic.com/shop
So this way I only have one WP installation and blog posts would be accessible via pcelarstvopejcic.com/blog/POST and pages in pcelarstvopejcic.com/PAGE
To do this, edit the functions.php file of your active theme and add:
add_filter('page_link', 'pages_in_root_page_link');
function pages_in_root_page_link($url) {
$parsed_url = parse_url(get_home_url());
return str_replace($parsed_url['path'] . '/', '/', $url);
}
then inside the .htaccess file change the default WP .htaccess file to:
# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^shop/?$ /blog/about/ [L]
RewriteRule ^contact/?$ /blog/contact/ [L]
RewriteRule . /index.php [L]
# END WordPress
Where shop and contact are page names.
Was this post helpful?
Let me know if you liked the post. That’s the only way I can improve. 🙂