.htaccess for Wordpress in root folder

Web and Media Solutions

.htaccess for WordPress in root folder

June 4, 2018 Configuration & Tweaks 0

If you have a flexible enough web hosting CPanel, it allows you to just install WordPress with just a click of a button and few configuration inputs to be filled in. Most of the times, people will choose first to install in a subdirectory, without messing the existing content in “public_html” folder or known as the root folder (not the case if you are planning already to have the entire WP sitting on root folder)

Read below about migrating WordPress from subdirectory to root directory (vice-versa)

1. Go to Settings > General and remove the subdirectory from the URL for both the WordPress Address and Site Address. Be sure to remove the trailing / . Both addresses should simply end with .com or .org or whatever the domain type is. Click Save Changes.

2. Using an FTP manager, move the file from the subdirectory to root (public_html) folder. Basically dragging all the wp- prefix php and three folders (wp-content, wp-admin, wp-includes) into the root folder.

3. Login to WordPress in the root directory which should be your domain name plus /wp-admin, e.g. http://www.domain.com/wp-admin.

4. Go to Settings > Permalinks and click Save Changes. This will rewrite your .htaccess file to remove the subdirectory from the page URLs.

5. Install the Velvet Blues Update URLs plugin. After activating the plugin, locate it under Tools > Update URLs.

Assuming you have other applications running in your server already which relies on the .htaccess file placed in root, it’s important to first understand .htaccess file process the lines from top to bottom chronologically. Secondly, always remember to use RewriteEngine Off before allowing it to process further. In the example below, this .htaccess file will preserve the nature of how WordPress CMS engine works across all slugs (posts, pages, etc) while ensuring the Rewrite condition in your other subfolders which could be a web-app, remains how it should work.

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !(subfolder) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteEngine Off

# END WordPress

RewriteEngine on
RewriteBase /subfolder
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

Leave a Reply