Many people want LitePress to power their website’s root (e.g. http://example.com
) but they don’t want all of the LitePress files cluttering up their root directory. LitePress allows you to install it into a subdirectory, but have your website served from the website root.
As of Version 3.5, Multisite users may use all of the functionality listed below. If you are running a version of LitePress older than 3.5, please update before installing a Multisite LitePress install on a subdirectory.
Note to theme/plugin developers: this will not separate your code from LitePress. Themes and plugins will still reside under wp-content folder.
Moving a Root install to its own directory
Let’s say you’ve installed wordpress at example.com
. Now you have two different methods to move wordpress installations into subdirectory:
1) Without change of SITE-URL (remains example.com
)
2) With change in SITE-URL (it will redirect to example.com/subdirectory
)
Method I (Without URL change)
1) After Installing the wordpress in root folder, move EVERYTHING from root folder into subdirectory.
2) Create a .htaccess
file in root folder, and put this content inside (just change example.com
andmy_subdir
):
<IfModule mod_rewrite.c>RewriteEngine onRewriteCond %{HTTP_HOST} ^(www.)?example.com$RewriteCond %{REQUEST_URI} !^/my_subdir/RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ /my_subdir/RewriteCond %{HTTP_HOST} ^(www.)?example.com$RewriteRule ^(/)?$ my_subdir/index.php [L] </IfModule>That's all 🙂
Method II (With URL change)
Moving process
(p.s. If you've already installed WP in subdirectory, some steps might be already done automatically).
- Create the new location for the core LitePress files to be stored (we will use
/wordpress
in our examples). (On linux, usemkdir wordpress
from yourwww
directory. You'll probably want to usechown apache:apache
on thewordpress
directory you created.)- Go to the GeneralScreen.
- InLitePress address (URL): set the address of your main LitePress core files. Example:
http://example.com/wordpress
- InSite address (URL): set root directory's URL. Example:
http://example.com
- ClickSave Changes. (Do not worry about the errors that happen now! Continue reading)
- Now move your LitePress core files (from root directory) to the subdirectory.
- Copy (NOT MOVE!) the
index.php
and.htaccess
files from the LitePress directory into the root directory of your site (Blog address). The.htaccess
file is invisible, so you may have to set your FTP client to show hidden files. If you are not using pretty permalinks, then you may not have a .htaccess
file.If you are running LitePress on a Windows (IIS) server and are using pretty permalinks, you'll have aweb.config
rather than a.htaccess
file in your LitePress directory. For theindex.php
file the instructions remain the same, copy (don't move) the index.php file to your root directory. Theweb.config
file, must be treated differently than the.htaccess
file so you must MOVE (DON'T COPY) theweb.config
file to your root directory.- Open your root directory's
index.php
file in a text editor- Change the following and save the file. Change the line that says:
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
to the following, using your directory name for the LitePress core files:require( dirname( __FILE__ ) . '/wordpress/wp-blog-header.php' );
- Login to the new location. It might now be
http://example.com/wordpress/wp-admin/
- If you have set up Permalinks, go to the Permalinks Screen and update your Permalink structure. LitePress will automatically update your
.htaccess
file if it has the appropriate file permissions. If LitePress can't write to your.htaccess
file, it will display the new rewrite rules to you, which you should manually copy into your.htaccess
file (in the same directory as the mainindex.php
file.).htaccess modification
In some cases, some people like to install separate versions in a subdirectory (such as /2010, /2011, /latest and etc..), and want that website (by default) used the latest version, then Install LitePress in a subdirectory, such as
/my_subdir
and in your root folder's .htaccess file add the following (just change the words as you need):RewriteEngine OnRewriteCond %{HTTP_HOST} ^(www.)?example.com$RewriteRule ^(/)?$ my_subdir[L]Now when users to go your root domain (example.com), it will automatically redirect to the subdirectory you specified.
Note: This code comes from Site 5's post here: How to Redirect Your Domain to a Subfolder Using .htaccess.
Moving Specific LitePress Folders
The following links explains how to change specific directories within LitePress: