How to Redirect Your Main Domain to a Subfolder on Hostinger (hPanel)

By default, Hostinger serves your website files directly from the public_html directory. However, there are several scenarios where you might want to set a subfolder as your website's "root" directory:

  • Project Isolation: Managing multiple projects within a single hosting plan.
  • Cleaner File Structure: Keeping your core application files separate from logs or other system files.
  • Seamless Deployment: Developing a new version of your site in a folder like /v2 and launching it without moving hundreds of files.

In this guide, we will walk you through the process of using an .htaccess file to redirect your main domain to any subfolder of your choice.


1. The Core Concept: How It Works

Since the public_html folder is a system-defined directory that cannot be renamed, we use a "rewrite" strategy:

  1. Place your files in a subfolder (e.g., public_html/main_site).
  2. Configure a rewrite rule in the primary .htaccess file (located in public_html).
  3. The Result: When a visitor types yourdomain.com, the server silently serves files from the subfolder without changing the URL in the browser's address bar.

2. Preparing Your Folder Structure

Before editing any files, ensure your directory is organized. Here is a typical example:

public_html/
├── .htaccess       ← The "Router" (we will edit this)
├── main_site/      ← Your actual website folder
│   ├── index.php
│   ├── assets/
│   └── ...

Pro Tip: Replace main_site with your preferred folder name, such as app, web, or dist.


3. Configuring the .htaccess File

Step 1: Access the File Manager

  1. Log in to your Hostinger hPanel.
  2. Navigate to Files → File Manager.
  3. Enter the public_html directory.

Step 2: Edit or Create .htaccess

  • If it exists: Right-click the .htaccess file and select Edit.
  • If it doesn’t exist: Click the "New File" icon and name it exactly .htaccess.

4. Implementation: The Rewrite Rules

Option A: Standard Redirection

Use this code if you have a standard HTML or PHP site. Copy and paste this into the .htaccess file inside public_html:

RewriteEngine On

# 1. Replace example.com with your actual domain
RewriteCond %{HTTP_HOST} ^example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]

# 2. Replace 'main_site' with your subfolder name
RewriteCond %{REQUEST_URI} !^/main_site/

# 3. Handle the rewrite
RewriteRule ^(.*)$ /main_site/$1 [L]

Option B: For WordPress, Laravel, or Other Frameworks

If your website (inside the subfolder) has its own .htaccess file for routing (like WordPress Permalinks or Laravel's index.php routing), you don't need to change the subfolder's file.

The primary .htaccess in public_html acts as a gateway, while the .htaccess inside your subfolder handles the internal application logic.


5. Troubleshooting Common Issues

If you encounter a 500 Internal Server Error or a "Too Many Redirects" loop, check the following:

  • Case Sensitivity: Linux servers treat Main_Site and main_site as different folders. Ensure the names match exactly.
  • Trailing Slashes: Ensure your RewriteCond for the folder name starts with / and ends with /.
  • Existing Rules: If you have existing code in your .htaccess (like SSL forced redirects), place the subfolder rewrite rules at the very top of the file.
  • Missing Index: Ensure an index.php or index.html file actually exists inside your subfolder.

6. Summary: Why Use This Method?

Using a subfolder redirect is a professional way to manage your hosting environment. It provides flexibility for future updates and keeps your public_html root clean, especially if you plan to host secondary tools (like a blog or a staging site) alongside your main application.

Date :
06 January 2026, 07:45
Author :
Copyright © 2025 Akhmad.dev