Deprecated: version_compare(): Passing null to parameter #2 ($version2) of type string is deprecated in /var/www/html/wpxss.com/application/wp-content/plugins/tweet-old-post-pro/vendor/codeinwp/themeisle-sdk/load.php on line 24

Deprecated: version_compare(): Passing null to parameter #2 ($version2) of type string is deprecated in /var/www/html/wpxss.com/application/wp-content/plugins/tweet-old-post-pro/vendor/codeinwp/themeisle-sdk/load.php on line 29

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the pb-seo-friendly-images domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/html/wpxss.com/application/wp-includes/functions.php on line 6260

Deprecated: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in /var/www/html/wpxss.com/application/wp-content/plugins/wp_glossary/includes/class-wpg-linkify.php on line 316
How to move WordPress pages to the Domain Root - wpXSS

Deprecated: Function wp_get_loading_attr_default is deprecated since version 6.3.0! Use wp_get_loading_optimization_attributes() instead. in /var/www/html/wpxss.com/application/wp-includes/functions.php on line 6260
.htaccess » How to move WordPress pages to the Domain Root

How to move WordPress pages to the Domain Root


Deprecated: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in /var/www/html/wpxss.com/application/wp-content/plugins/wp_glossary/includes/class-wpg-linkify.php on line 316

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.

See also  How to hide a plugin from the WordPress plugins list 🙈

Was this post helpful?

Leave a Comment

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.

Recommended