Server Gigabit Guide

Restructuring Your Website with htaccess Rewrites: A Step-by-Step Tutorial

You are here:
Estimated reading time: 1 min

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

  1. Start with a fresh account or create a full backup of your files.

  2. Create a sub-folder in /public_html and name it after the domain, e.g. example.com.

  3. Move all content of your main domain to the newly created folder.

  4. If there already is a .htaccess file, move it as well.

htaccess Configuration

  1. 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]
  1. Replace example.com with your actual domain name.

  2. Save the file and open the domain in your browser. The website should be displayed correctly.

Updating Website Configuration (Joomla!)

  1. Modify the following line in configuration.php:
public $live_site = 'https://www.example.com/';
  1. 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)

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

Was this article helpful?
Dislike 0
Views: 4