Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
META: I don't understand how I lost 90 reputation from this question? –  dmanexe Jan 6 at 19:28

3 Answers 3

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.

share|improve this answer
    
user35541, yes it is a problem that might occur if one is not updating with caution, but either way it should be done with some sort of hack, since it is not how WP is designed to work. Whether choosing to hard code it or building custom htaccess is up to the developer. I personally, would not recommend developing with WP as an addon to another application, but if it is dmanexe's only solution we're here to provide an adequate answer. Both of our suggestions might work in his environment and both have pros and cons. :) –  Сър Георги Демирев Jul 19 '13 at 21:30

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.

share|improve this answer
    
Yes, @Сър Георги Демирев, plugins modify core files indirectly, but there is a huge diference in modify file directly and indirectly. What about I update WP by FTP and I (or any other developer / designer having ftp access) forget to delete index.php from new wordpress installation? –  G. M. Jul 19 '13 at 20:48

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!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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