Managing multiple domains and their associated content can become cumbersome, especially when the content is spread across different folders. This can lead to confusion and make it difficult to maintain a consistent and organized website structure. To address this issue, htaccess rewrites offer a powerful solution for moving website content to a subfolder without affecting its appearance or functionality.
This guide provides a detailed explanation of how to utilize htaccess rewrites to achieve a cleaner and more organized website structure. It outlines the steps involved in moving website content to a subfolder, configuring the necessary settings, and ensuring seamless operation of the website. Additionally, it provides specific instructions for configuring Joomla! 3 and WordPress to work effectively with the new folder structure.
By following this guide, you can effectively manage your website’s content, maintain a clean and organized file structure, and enhance the overall user experience.
Preparation
-
Start with a fresh account or create a full backup of your files.
-
Create a sub-folder in /public_html and name it after the domain, e.g. example.com.
-
Move all content of your main domain to the newly created folder.
-
If there already is a .htaccess file, move it as well.
htaccess Configuration
- Create a new .htaccess file in /public_html and paste the following:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !^/example.com
RewriteRule ^(.*)$ example.com/$1 [L]
-
Replace example.com with your actual domain name.
-
Save the file and open the domain in your browser. The website should be displayed correctly.
Updating Website Configuration (Joomla!)
- Modify the following line in configuration.php:
public $live_site = 'https://www.example.com/';
- If you use URL Rewriting in Joomla!, edit the following line in the .htaccess file in the sub-folder of your domain:
RewriteBase /example.com
Updating Website Configuration (WordPress)
- Modify the following lines in wp-config.php:
define('WP_HOME','https://example.com');
define('WP_SITEURL','https://example.com');
Conclusion
By implementing these steps and making the necessary adjustments, you can successfully move your website’s content to a subfolder without affecting its appearance. The new folder structure will be more organized and easier to manage.