WordPress within specific sub-directories, implicitly not root

I have an existing application running at my website root now. Using .htaccess, would it be possible for a single WordPress installation to manage sub-directories? For example, /press/, /careers/, /blog/ would be served by WordPress. The problem is I don’t want WordPress to get served on the root. I suspect something tricky with permalinks and .htaccess.

Option 2 for us here is building a CRUD into our app, but we really wanted to use WordPress (for certain pages).

Related posts

3 comments

  1. Try this:

    Rename your index.php (inside WordPress root folder) to index_.php or wordpress_index.php or whatever. This way you can load your current application, not the WordPress index. After that, open .htaccess in an editor and change it from something like this:

    # 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>
    # END WordPress
    

    to this:

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

    Where it says index.php change it to the new name of the index file. This way, all other pages and permalinks will work, but your index will be your old application.

    note:
    user35541’s solution is good, but every time you want to add another page, you’ll have to once again add it manually to .htaccess. Plus if user35541’s statement that editing core files is bad was right, there would be no plugins for WP (which is virtually editing core files indirectly). The only problem in editing core files directly is that they will be overwritten if you update, but since you’re renaming a file (or creating a new one you if you will) it would not be affected.

  2. Modify (even rename) WP core files is never a good practise.

    Try this instead:

    Install WordPress in a phisical subfolder in your site root, (e.g. /WP).

    After that, in the .htaccess file in the root folder of your site insert something like this:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule blog/(.*) WP/press/$1 [L]
    RewriteRule press/(.*) WP/press/$1 [L]
    RewriteRule careers/(.*) WP/careers/$1 [L]
    RewriteRule anything_here/(.*) WP/anything_here/$1 [L]
    </IfModule>
    

    Off course, add a rewrite rule for every (virtual) subfolder you want to serve with wordpress.
    Virtual subfolders can represent pages, categories or anything else in wordpress.

    Don’t forget to enable pretty permalinks in wordpress.

    In this way only your current application resides in the root folder and everithing is well organized and maintainable.

    Update:
    In this solution, adding a new WP page means add a new .htaccess rule. A workaround is to use a general parent page: create a page named ‘Pages’ (slug ‘pages’) then create every other page as a child of this page.

    In .htaccess add:

    RewriteRule pages/(.*) WP/pages/$1 [L]
    

    now every page that is child (even grandchild) of ‘Pages’ will be served correctly.

  3. You can use Apache’s mod_alias to accomplish this. Before moving on, ensure that your server has that installed. The easiest way is to open your apache config and search for “alias”. You should have a line like this, uncommented:

    LoadModule alias_module libexec/apache2/mod_alias.so
    

    Next, in your apache config (or virtual host config for the site in question), add the following block, replacing “/var/www/wordpress” with the path to your WordPress installation:

    aliasMatch ^(/wp-.*) /var/www/wordpress$1
    aliasMatch ^/(blog|careers|press).* /var/www/wordpress/index.php
    <Directory /var/www/wordpress>
        Options Indexes MultiViews FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    

    Restart apache, and like magic it should just work!

Comments are closed.