I have an Apache2 web site with several different resources all installed directly under the DocumentRoot:

GOAL: I'd like for users to go to WordPress automatically, by typing http://example.com, instead of http://example.com/wordpress. But I also need to be able to access the other resources off the root. For example, the URL http://example.com/mycodeigniterapp still needs to work as-is?

Q: What's a good way to "hide" the word "wordpress" from the URL, without "breaking" any existing functionality?

Thank you in advance!

3 Answers 3


Set your document root to your WordPress directory.

DocumentRoot /path/to/webroot/wordpress/

Of course, this will make all other subdirectories unreachable. To fix this you have two possibilities:

  1. Move all other directories into the WordPress dir
  2. Use Aliases for the other directories

Option 1 is less work regarding the configuration, but creates a mess on the filesystem. WordPress itself doesn't care if there are foreign files and directories mixed with the WordPress files, but you will have to know which files do not belong there.

Option 2 is cleaner, but you will have to create an alias in your apache config every time you add something new:

Alias /phpmyadmin /path/to/webroot/phpmyadmin
Alias /mycodeigniterapp /path/to/webroot/mycodeigniterapp

Note: This will break the WordPress links at first. WordPress stores absolute URLs in the database and every post will still link to /wordpress/.... To fix this you simply need to log in, go to the permalink settings and click on the Save button. This will update all permalinks in the database.

See the documentation Moving WordPress on that topic.


Either you use folders to differentiate the apps, as is currently the case, or you can use different URLs, e.g.

  • sql.example.com
  • blog.example.com
  • ...

I would not attempt putting the files of the different applications in the same root folder nor would I attempt to create complex rewrite rules. These will fail as different applications will have the same filenames (all will have an index.php and a config.php for example). Additionally, this will make updating an application a lot more complex.


This would mean creating several DNS A records all pointing to the same IP address - the one your server is listening on. Next you'll create several VirtualHost statements, each with their own DocumentRoot. An example would be:

<VirtualHost *:80>
  ServerName sql.example.com
  DocumentRoot /var/www/html/phpmyadmin
  # ...
<VirtualHost *:80>
  ServerName blog.example.com
  DocumentRoot /var/www/html/wordpress
  # ...

Edit 2:

Regarding WordPress, perhaps this link might be useful to move your wordpress site from a subdirectory to the root of the (sub)domain: https://askwpgirl.com/move-wordpress-from-subdirectory-to-root-directory/

  • Thank you. Let me clarify: the different resources ("mycodeignigerapp", "wordpress", etc.) already have different folders under "/var/www/html", including "/var/www/html/wordpress". Q: Does that affect your answer? Do you still suggest "virtual host" for each resource?
    – paulsm4
    Oct 11, 2018 at 6:30
  • This is a good solution, just be advised that my note below my answer about breaking WordPress links also applies here. Oct 11, 2018 at 7:09
  • @paulsm4: I edited my reply a bit. Does that clarify things for you? @GeraldSchneider: Perhaps it does. I'm not familiar with wordpress. Instead of your fix with the save action, I assume you'ld also be able to write a Rewrite statement?
    – Tommiie
    Oct 11, 2018 at 7:46
  • @Tom Why would you want to have a rewrite that has to be executed on every request to circumvent a symptom when you can fix the cause of a problem it with a single click on a button? Oct 11, 2018 at 7:52

what is at your web root if you go to http://example.com ? Usually that's a default index page like index.php or index.html. Or you can create a page like that and use it, or you can use a .htaccess file and mod_rewrite.

So in order of easy/fast:

  1. Using a redirect from a index.php file (create or edit index.php in http://example.com). This only works if PHP is set up on your server, but obviously it is for your wordpress to work. Create the index.php file with:

    <?php header('Location: http://example.com/wordpress/'); ?>
  2. How we did it in the 1990s - The super old school way: In a default HTML index file, use the META Refresh tag. No PHP required. Create http://example.com/index.html and edit:

    <head><meta http-equiv="refresh" content="0;URL=http://example.com/wordpress/"></head>
    <body>If your browser does not refresh you, <a href="/wordpress/">Click here</a>.</body>
  3. Using .htaccess and mod_rewrite - Edit the ".htaccess" file at the web root of example.com. If there isn't one, create a new file named .htaccess. Add:

    RewriteEngine On
    RewriteRule ^ http://example.com/wordpress [L,R=301]

Note: If #3 makes the site show the White Screen of Death (WSOD) on every page, you probably need to enable mod_rewrite with sudo a2enmod rewrite && sudo apachectl restart. Or if you have no idea what sudo means, maybe try method 1 or 2.

  • Thank you all for your help. Professor Falken - I love your sig. Quoting "War Games" and "2001" in the same sig ;)
    – paulsm4
    Oct 12, 2018 at 5:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.