WordPress in a subdirectory, urls like it was in root directory

There are many reasons to install wordpress in a subdirectory and not in the root directory (for instance because it is easier to update wordpress, the files are better organized …). However, for SEO purposes, it is recommended to mask that subdirectory name in url and make wordpress look like it is installed in the root directory

So, lets suppose you install wordpress in a subdir called wordpress. Then all of your urls will look like:
http://www.yoursitename.com/wordpress/...

And we want to remove that trailing /wordpress so our urls look like:
http://www.yoursitename.com/...

Note: If you want to have permalinks active and still don’t have done this, please activate your permalinks first!!. I have set a Custom Structure (/%category%/%postname%/).

Ok, ready to go. Let's continue with the process.

You will have to change two files:

First, edit wp-config.php and add these following two lines (change the word 'wordpress for your subdirectory name):

1
2
3
// ** Hostname settings ** //
define('WP_SITEURL', "http://${_SERVER['HTTP_HOST']}/wordpress");
define('WP_HOME',    "http://${_SERVER['HTTP_HOST']}");

Then copy your /wordpress/index.php to your root directory and modify it. Change the line that says:

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

for

1
2
/** Loads the WordPress Environment and Template */
require('./wordpress/wp-blog-header.php');

If you had permalinks activated (this is, not default behaviour) copy the existing /wordpress/.htaccess file to root directory!. If you don't, when you try to access category links, they won't work.

That's all folks! ;)

Related posts:

  1. WordPress: remove /category
  2. A real case example: my .htaccess in /wordpress subdirectory
  3. WordPress Yoast SEO + wp_comfy theme + Category titles
  4. Añadir meta-información a wordpress
  5. wordpress anti-spam plugins, captchas and more

One Response to “WordPress in a subdirectory, urls like it was in root directory”

  • Ranui says:

    Hi there

    Man – you saved my life on this one! Ive been trying to do htaccess, mod rewrites, etc for about 6 months on and off – looking at cPanel and Apache systems etc trying to figure this out – and your solution was the simplest – many thanks.

    Id like to repay the favour – Im a graphic designer, so if you need a smallish job done – logo, business cards – whatever – just let me know

    Thanks

    Ranui

Leave a Reply

Paypal donate

Please help me keep this blog up by donating.

Por favor, ayúdame a continuar con el blog donando.