24/7 HUMAN WORDPRESS WATCH · SAN DIEGO, CA · SINCE 1998
HackGuard.com Managed WordPress Security with Heart
TOPIC CLUSTER · BACKUPS & INFRASTRUCTURE

How to Remove a Subdirectory Name (like /wp/ or /blog/) from Your WordPress Address

Jim Walker By Jim Walker, The Hack Repair Guy™ Updated Topic: WordPress Backups, Hosting Isolation & Migrations
Quick Answer

You can serve a subdirectory WordPress install from your root domain without moving every file: update the Site Address (URL) in Settings > General, copy index.php and .htaccess to your root /public_html/ folder, and update the require path in root index.php to point to your subfolder.

How to Remove a Subdirectory Name (like /wp/ or /blog/) from Your WordPress Address
Built your WordPress site inside a subfolder like /new/ or /wp/? Here is how to serve it from your root domain URL.

Why this matters for your WordPress site

Our domain for this example will be "your-domain-name.com"

Within the public directory, often named public_html or html, you should see the following settings for a standard WordPress permalinks setup:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

The above works perfectly fine when your main domain name is located at the top of your public directory, not so well if your site is located in a subdirectory like "blog"

The first file we'll edit is the .htaccess file (contents shown above), to:

Step-by-step setup and recommendations

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?your-domain-name.com$
RewriteCond %{REQUEST_URI} !^/blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /blog/$1
RewriteCond %{HTTP_HOST} ^(www.)?your-domain-name.com$
RewriteRule ^(/)?$ /blog/index.php [L] 
</IfModule>
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/blog/wp-blog-header.php' );
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

# END WordPress

Display your website in the web browser location bar as the domain name only and not show the trailing subdirectory /blog

And allow you to access your WordPress dashboard as simply www.your-domain-name.com/wp-admin/ instead of www.your-domain-name.com/blog/wp-admin/

If you have further questions, just pick up the phone and call, (619) 479-6637, or email [email protected].

Enjoy! Moving to a different domain name as well? See how to migrate WordPress to a different domain name.

Common mistakes to avoid

Awesome Jim. Helping all the poor folks out there.

fortboise says: September 18, 2017 at 11:56 am I did find this useful, thank you. For modifying an existing site with subdirectory (/wp/) "showing," to hiding the sub, I wasn't able to infer the right info from the Codex page about subdirectory setup. Turned out our docroot index.php and the wp/.htaccess were good to go as they were. (I had the docroot .htaccess correct from reading the Codex page.) One quirk remains, however. Our wp-admin and such remain where they were with the /wp/ subdirectory showing. We weren't looking to "accomplish the goal" #2 shown above, but I did kind of expect that to happen. We changed from http to all https at the same time (having previously set the wp-admin to use https, in wp-config.php) and I the rendered page source has all site urls https... but resource links to css and js still have URLs with the /wp/ in them. We did modify our database (properly) to change all instances of http://domainname/wp/ to https://domainname/ Reply Jim Walker, The Hack Repair Guy says: September 27, 2017 at 11:02 am My other article on SSL may help in regard to ensuring all of the sub-links are set to https:// as well. See https://hackrepair.com/articles/wordpress/prepare-wordpress-blog-for-ssl Reply

I did find this useful, thank you. For modifying an existing site with subdirectory (/wp/) "showing," to hiding the sub, I wasn't able to infer the right info from the Codex page about subdirectory setup. Turned out our docroot index.php and the wp/.htaccess were good to go as they were. (I had the docroot .htaccess correct from reading the Codex page.)

One quirk remains, however. Our wp-admin and such remain where they were with the /wp/ subdirectory showing. We weren't looking to "accomplish the goal" #2 shown above, but I did kind of expect that to happen.

We changed from http to all https at the same time (having previously set the wp-admin to use https, in wp-config.php) and I the rendered page source has all site urls https... but resource links to css and js still have URLs with the /wp/ in them. We did modify our database (properly) to change all instances of http://domainname/wp/ to https://domainname/

Jim Walker, The Hack Repair Guy says: September 27, 2017 at 11:02 am My other article on SSL may help in regard to ensuring all of the sub-links are set to https:// as well. See https://hackrepair.com/articles/wordpress/prepare-wordpress-blog-for-ssl Reply

My other article on SSL may help in regard to ensuring all of the sub-links are set to https:// as well. See https://hackrepair.com/articles/wordpress/prepare-wordpress-blog-for-ssl

Frequently asked questions

What is the fastest way to fix or prevent this issue on my WordPress site?
You can serve a subdirectory WordPress install from your root domain without moving every file: update the Site Address (URL) in Settings > General, copy index.php and .htaccess to your root /public_html/ folder, and update the require path in root index.php to point to your subfolder.
Can HackGuard.com handle backups & hosting for my WordPress site?
Yes. For $14.95/month (or $49.85/month for up to 10 sites), Jim Walker and the HackGuard team perform a 9-point manual security and database overhaul in Week 1, test all core and plugin updates weekly by hand, maintain 60-day offsite cloud backups, and back your site with a free HackRepair.com cleanup guarantee. Call Jim directly at (619) 479-6637.
Jim Walker, The Hack Repair Guy

Written and reviewed by Jim Walker, The Hack Repair Guy™

Jim Walker has protected and repaired WordPress websites since 1998. Want Jim to handle your WordPress security, weekly updates, and 60-day offsite cloud backups for 50 cents a day?

Client Video Story