• Skip to primary navigation
  • Skip to main content

Managed WordPress Security for Pennies a Day. Call (619) 479-6637

Managed WordPress Security with Heart

MENUMENU
  • Why HackGuard.com? Why Choose HackGuard.com?
  • HackGuard.com WordPress Managed Services Rates WordPress Managed Services Rates
  • HackGuard.com Articles HackGuard Articles Library
    • Hack Guard Customer Testimonials
    • Top 20 WordPress Plugins to Avoid
    • Why Should I Maintain My Own WordPress Website’s Backups?
    • How to Improve Junk Email Filtering at Gmail
    • WordPress 6.0.3 Security Release – Updated?
    • About that “Weekly jQuery Migrate Status Update” email
    • How to Change a WordPress User from Subscriber to Administrator Role
    • WordPress 4.9.3 – Going into the tunnel and never coming out…
    • How Do I Migrate WordPress to a Different Domain Name?
    • Community Blogging: A Short Guide
    • WordPress Troubleshooting and How to Fix WordPress Errors
    • Is My Web Host Secure? Maybe not…
    • How to remove the subdirectory name from your WordPress website address
    • How can I improve the performance of my WordPress website?
    • How can I improve the performance of my WordPress blog (Part 2)
    • Protecting WordPress Against Brute Force Attacks
    • How do I reset my WordPress password?
    • How To Clear Cron Jobs in WordPress
    • xmlrpc.php and Pingbacks and Denial of Service Attacks, Oh My!
    • Free Website Monitoring Services, well, mostly free...
    • How to choose a secure web hosting company for a WordPress website
    • WordPress 404 Page Setup - Do You Have Five Minutes?
    • Can mod_pagespeed Improve Page Load Speed (external link)?
    • Yoast WordPress SEO Settings and Recommendations
    • Is Your Mom Missing Her BUMM?

How to remove the subdirectory name from your WordPress website address

In this example of subdirectory redirection, we’ll be using .htaccess to properly redirect a website address such that both the website and WordPress dashboard load without the subdirectory name.

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>

Removing the subdirectory blog from your URLThe 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”

 

To enable your website to function properly within your blog subdirectory, but without showing the blog subdirectory name, we actually need to change three different files, shown in the picture at right:

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

<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>

 

The second will be the index.php file, from:

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );

to:

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/blog/wp-blog-header.php' );

 

And lastly, open the blog directory, then edit the .htaccess file within to:

# 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

 

Updating these three files, as shown above, will accomplish two goals:

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

Numero 2And 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/

 

I hope you’ve found this short tutorial on how to set up a WordPress site within a subdirectory without displaying the subdirectory within Google search or the WordPress dashboard helpful.

If you have further questions please feel free to leave your comments or questions below.

Enjoy!

 

Share me:

  • Tweet
  • Email
  • Print

Like this:

Like Loading...

Filed Under: Call (619) 479-6637 Tagged With: .htaccess, index.php, wordpress subdirectory

Reader Interactions

Comments

  1. techiedesigner says

    February 6, 2017 at 10:34 am

    Awesome Jim. Helping all the poor folks out there.

    Reply
    • 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

Please feel free to comment via WordPress, Twitter, Facebook or Google+ Cancel reply

Proactive WordPress Security Management for Pennies a Day™

© Copyright 2022 HackGuard.com™, HackRepair.com™,
The Hack Repair Guy™, Hack Repair Guy™
Copyright and Trademark Statement | Privacy Policy

Call HackRepair.com for website security help, (619) 479-6637.
Content Approved By Jim Walker, The Hack Repair Guy
%d bloggers like this: