I may be completely alone in this, but I've never been a fan of installing anything straight in to the root directory on a web server. I've always opted for installing various bits of software in to their own subdirectories.

This has served me particularly well if I've needed to install several different bits of software on the same website, for example a piece of forum software to run alongside an existing CMS. Everything stays neat and tidy in its own subdirectory.

It also works really well for developing something new alongside an existing live enviroment. You can work peacefully inside the subdirectory, and even use .htaccess to restrict access to protect the innocent. When you're ready to go live, you can redirect traffic from your root directory to the subdirectory.

So I finally decided to publish my new website, and went about redirecting my root directory to the subdirectory where I had installed WordPress. I have my own method for doing this, but I decided to see what the official WordPress documentation says.

It details two main methods. The first method describes copying the index.php & .htaccess file to the root directory, tweaking the source code of the index.php file, and then changing the Site Address (URL) in Settings > General to remove the subdirectory. The subdirectory then becomes transparent to visitors, who would be able to browse the website on URLs such as http://marktyrrell.com/about.

The second method describes using a simple .htaccess file in your root directory, to redirect visitors to the subdirectory. Using this method, visitors would see the subdirectory in all URLs, you're simply redirecting anyone that lands on the root URL straight in to that subdirectory.

I opted to stick with my own method which I have been using for a long time, and works with various pieces of web software. To use this method with WordPress you first change your Site Address (URL) in Settings > General, removing the subdirectory to show something like http://marktyrrell.com. Ignore the error message you get after clicking save. You now create the following .htaccess file in your root directory (obviously modifying it to your domain and directory).

# Turn on rewrites.
RewriteEngine on

# Don't apply to URLs that go to existing files or folders.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Only apply to URLs that aren't already under /wp.
RewriteCond %{REQUEST_URI} !^/wp/

# Rewrite all those to insert /wp.
RewriteRule ^(.*)$ /wp/$1

# Redirect the root folder.
RewriteCond %{HTTP_HOST} ^(www.)?marktyrrell.com$
RewriteRule ^(/)?$ wp/ [L]

Importantly, clear your web browser cache and delete any cookies for the domain. After you've done this navigate to your website root directory, and you should see your WordPress installation sans the subdirectory in the URL.

I prefer this method as I wasn't too keen on copying and modifying the index.php file. If anyone knows of any potential drawbacks to my method, or why going down the modified index.php route is better, drop me a line in the comments.

  • wwian

    This method worked. Thanks!

  • Jason Leone

    Just tried and kept getting 500 internal server errors. Used your text and replaced “wp” with my subdirectory and still no luck.

    • David

      Ensure you change the Site Address from domain.tld/www to domain.tld and ensure after you have done this update your custom .htaccess file in the root and remove the additional script that WP has added.

  • https://twitter.com/gersonapablaza Gerson

    thank you ver much! your method worked like a charm!

  • Johann Schröder

    Worked for me as well after I deleted all my cpanel redirects.

  • David


    I would suggest CHMOD your .htaccess file to 444 to prevent WordPress overwriting the file.

  • Dave

    Hey, great post.

    How would someone achieve this on IIS server?

    Would would the web.config file need to contain?

  • Warren

    Awesome well done!

  • Logic Flow

    Thanks!! Works much better than the offical documention!

  • Rus

    Hey Mark, are there any security vulnerabilities that would result in your method? I noticed the original root htaccess file had config.php and common.php permissions to deny.

  • Siva


    Its working fine. but when am trying to access wp-admin, it just asked the login details. once i given the details and hit submit again it shows login form only. can’t access dashboard. clarification please.

    • Jesse

      Yeah, I’m having the same issue. I have to login through the wordpress themes user login before the admin ribbon appears. Then, I can click on the dashboard link. I haven’t found a proper solution.

  • bunny

    Nice job! thanks bro <3

  • Madhavi Jha

    Thank You ,
    I am struggling with its last 3 days
    all step have completed as article “Giving WordPress Its Own Directory”, but home page not working , with using your tips ,its work perfectly.
    Thank you once again.