Install WordPress Files and Blog in Different Directories
The Wordpress installation guide and the Moving Wordpress page in the Wordpress Codex detail how you can install Wordpress in one directory, eg https://www.domain.com/wordpress/
and access your blog from another, or from the base address or your site - eg https://www.domain.com.
These details are all well and good except for one thing - the caveats. Both these pages quote:
The only catch is the "Edit this" links will no longer appear by every entry and comment if you're using this option. This is a limitation of how we're setting cookies, and this may be fixed in the future.
Sorry, this isn't good enough. I use the WP cookie in several places on my site so I need it to work, and all the time, whilst still keeping my files neat and tidy.
So, after a little bit of testing, I found that the following does the trick just perfectly...
1. Install and setup WP so that the Wordpress URI and the Blog URI point to the WP install directory - eg https://www.domain.com/wordpress/
2. Edit the wp-includes/classes.php
file and comment out lines 1244, 1245, 1246 and 1248 thus leaving it looking as follows:
// if (strstr($query, $this->index)) {
// $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]n";
// } else {
$rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA,L]n";
// }
This is just editing the mod_rewrite_rules()
function, so the same work-around can be applied to other versions of WP.
3. Go to Option -> General
4. Set Blog Address to your base URI - eg https://www.domain.com
5. Click Update Options. This should now create your .htaccess in the base directory of your site, not in /wordpress/
6. Edit the new .htaccess
file, and add the following BEFORE the # BEGIN WordPress
line:
RewriteRule ^$ /wordpress/ [QSA,L]
Thus making the beginning of your file look as follows:
RewriteRule ^$ /wordpress/ [QSA,L]
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
...
Note, you must change the /wordpress/
to where ever you chose to install WP.
7. Save the file.
That's it. You should find that all your RewriteRules point to /wordpress/index.php
and it will stay this way when you make any updates to your .htaccess
in the future, like adding pages etc.
Just one word of warning... these changes will be lost when you update WP to a later release (cos you're over-writing the classes.php file), but it's a small price to pay for neat, tidy convenience.
I could have coded round this, but I really couldn't be arsed. Commenting out 3 lines is way simpler. Who knows, maybe the WP authors will actually take this into account in the future. There is no reason why one should have to go through their steps and make a mess of things.
Update: The same steps apply in Wordpress 2.0, however the line numbers are now 1367, 1368, 1369 and 1371. You also need to change line 1376 to look as follows:
"RewriteRule . {$site_root}{$this->index}\n";
This ensures the .htaccess is updated with the correct root directory each time you make an edit.