Skip to content
Menu
DevSecOps Now!!!
  • About
  • Certifications
  • Contact
  • Courses
  • DevSecOps Consulting
  • DevSecOps Tools
  • Training
  • Tutorials
DevSecOps Now!!!

How to Redirect a Subdirectory to a Public Folder in cPanel

Posted on May 2, 2025

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

When deploying PHP or Laravel applications on shared hosting, it’s common to keep your application files outside the web root and serve only the public directory. If your app is in public_html/crm and the public entry point is in public_html/crm/public, you’ll want users who visit https://www.cmsgalaxy.com/crm/ to be redirected to https://www.cmsgalaxy.com/crm/public/. Here’s how to do it, with troubleshooting for common errors like directory listings, 404, and 403 errors.

Understanding the Problem

By default, when someone visits https://www.cmsgalaxy.com/crm/, Apache serves the contents of public_html/crm/. If there’s no index.php or index.html file, Apache will show a directory listing (as in your first screenshot). If directory listing is disabled, you might see a 403 Forbidden error (third screenshot). If you try to use rewrite rules that don’t match or point to missing files, you’ll see a 404 Not Found error (second screenshot).

The goal is to redirect all requests for /crm/ to /crm/public/.

Step 1: Prepare the Directory Structure

  • Your application should be in public_html/crm/.
  • The web-accessible files (like index.php, assets, etc.) should be in public_html/crm/public/.

Step 2: Create or Edit the .htaccess File in /crm

Open cPanel’s File Manager and navigate to public_html/crm/.
If there isn’t already a file named .htaccess, create one.
If it exists, edit it.

Paste the following code:

textRewriteEngine On

# Redirect only if the request is exactly /crm or /crm/
RewriteCond %{REQUEST_URI} ^/crm/?$
RewriteRule ^$ /crm/public/ [R=302,L]

This tells Apache:

  • If the request is for /crm or /crm/, redirect the browser to /crm/public/.
  • The [R=302,L] flag means this is a temporary redirect; change it to [R=301,L] for a permanent redirect after testing.

Step 3: Save and Test

  • Save the .htaccess file.
  • Visit https://www.cmsgalaxy.com/crm/ in your browser.
  • You should be redirected to https://www.cmsgalaxy.com/crm/public/.

Step 4: Troubleshooting Common Issues

If You Still See a Directory Listing

  • Make sure your .htaccess file is named correctly (with a dot at the start, no extension).
  • Check file permissions: .htaccess should be 644, and the crm folder should be 755.
  • Confirm that mod_rewrite is enabled on your server. Most cPanel hosts have this enabled by default.
  • If you have a parent .htaccess in public_html/, make sure it isn’t interfering. Parent rules can override or block subdirectory rewrites76.

If You See a 403 Forbidden Error

  • This usually means permissions are incorrect or .htaccess syntax is broken.
  • Double-check that the .htaccess file is readable and the folder is accessible.
  • Try removing all other rules from .htaccess except the redirect to isolate the issue.

If You See a 404 Not Found Error

  • Ensure that the public folder exists inside crm and contains an index.php or index.html.
  • Try accessing https://www.cmsgalaxy.com/crm/public/ directly. If that works, your redirect is fine.

Step 5: Alternative PHP Redirect

If .htaccess is not working due to server restrictions, create a file named index.php in public_html/crm/ with the following content:

php<?php
header("Location: /crm/public/");
exit;

This will redirect all visitors who land on /crm/ to /crm/public/ using PHP.

Step 6: Prevent Directory Listing

You may also want to prevent directory listing for security. Add this line to your .htaccess:

textOptions -Indexes

Step 7: Final Checklist

  • .htaccess file is in public_html/crm/
  • File permissions are correct (.htaccess = 644, folders = 755)
  • The public folder exists and is accessible
  • No conflicting rules in parent .htaccess
  • mod_rewrite is enabled

Step 8: Going Further

If you want to redirect all traffic under /crm (not just /crm/), you can expand the rule, but for most Laravel or PHP apps, only the base path needs to redirect to /public/. For more advanced routing, use internal rewrites, but for simple redirection, the above is safest and most reliable4913.

Conclusion

Redirecting /crm to /crm/public on cPanel is straightforward with a simple .htaccess rule. This approach keeps your application secure and ensures users always land on the correct entry point. If you run into errors, check permissions, syntax, and server configuration. For persistent issues, contact your hosting provider to confirm that .htaccess and mod_rewrite are supported.


Post Views: 946
  • .htaccess
  • 403 Forbidden
  • 404 Error
  • apache
  • cPanel
  • Directory Listing
  • File Permissions
  • How to Redirect a Subdirectory to a Public Folder in cPanel
  • Laravel Hosting
  • PHP Hosting
  • Redirect
  • SEO Redirects
  • Shared Hosting
  • Subdirectory Redirect
  • Web Hosting
  • Website Migration
Subscribe
Login
Notify of
guest
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
  • DevOps to Certified Site Reliability Professional: A Senior Mentor’s Guide
  • Certified Site Reliability Manager Training, Preparation, and Career Mapping
  • Certified Site Reliability Architect: The Complete Career Guide
  • What Is a VPN? A Complete Beginner-to-Advanced Tutorial
  • How to Install, Secure, and Tune MySQL 8.4 on Ubuntu 24.04 for Apache Event MPM and PHP-FPM
  • Complete Guide to Certified Site Reliability Engineer Career
  • Certified DevSecOps Professional Step by Step
  • Certified DevSecOps Manager: Complete Career Guide
  • Certified DevSecOps Engineer: Skills, Career Path and Certification Guide
  • Step-by-Step: Become a Certified DevSecOps Architect
  • Tuning PHP 8.3 for Apache Event MPM and PHP-FPM on Ubuntu: A Complete Step-by-Step Production Guide
  • Complete Step-by-Step Guide to Configure Apache Event MPM, Create index.php, Set Up VirtualHost, and Fix Ubuntu Default Page
  • Convert XAMPP Apache to Event MPM + System PHP-FPM
  • The Gateway to System Observability Engineering (MOE)
  • How to Finetune Apache and Prove It Works: A Real-World Guide to Testing Performance, Concurrency, HTTP/2, Memory, CPU, and Security
  • Building a High-Performance Apache Event MPM + PHP-FPM + MariaDB Stack (Advanced Server Optimization Guide)
  • Master Infrastructure as Code: The Complete Hashicorp Terraform Associate Guide
  • Building a High-Performance Apache Server with Event MPM + PHP-FPM (Step-by-Step Guide)
  • Is XAMPP Safer for Production Than Using Apache and PHP as Root? 2026 Practical Guide
  • Unlock Cloud Security Expertise with Certified Kubernetes Security Specialist (CKS)
  • How to Fix wpDiscuz Not Replacing Default WordPress Comments in Block Themes
  • Complete Guide to Certified Kubernetes Application Developer Certification
  • Overview of Certified Kubernetes Administrator (CKA) Certification
  • How to Install and Configure XAMPP on Ubuntu 24 Server (Latest Version – 2026 Complete Guide)
  • Mastering the Google Cloud Professional DevOps Engineer
  • Mastering Azure Cloud Security: The AZ-500 Path
  • Why AZ-400 is Essential for Global Cloud Engineering Roles
  • Webp format is not supported by PHP installation.
  • Reconfigure PHP 8.2.12 for XAMPP WITH WebP
  • How to Fix “WebP Format is Not Supported by PHP Installation” in XAMPP/LAMPP (Complete 2026 Guide)

Recent Comments

  1. digital banking on Complete Tutorial: Setting Up Laravel Telescope Correctly (Windows + XAMPP + Custom Domain)
  2. SAHIL DHINGRA on How to Uninstall Xampp from your machine when it is not visible in Control panel programs & Feature ?
  3. Abhishek on MySQL: List of Comprehensive List of approach to secure MySQL servers.
  4. Kristina on Best practices to followed in .httacess to avoid DDOS attack?
  5. Roshan Jha on Git all Commands

Archives

  • March 2026
  • February 2026
  • January 2026
  • December 2025
  • November 2025
  • October 2025
  • September 2025
  • August 2025
  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022

Categories

  • Ai
  • AI Blogging
  • AiOps
  • ajax
  • Android Studio
  • Antimalware
  • Antivirus
  • Apache
  • Api
  • API Security
  • Api Testing
  • APK
  • Aws
  • Bike Rental Services
  • ChatGPT
  • Code Linting
  • Composer
  • cPanel
  • Cyber Threat Intelligence
  • Cybersecurity
  • Data Loss Prevention
  • Database
  • dataops
  • Deception Technology
  • DeepSeek
  • Devops
  • DevSecOps
  • DevTools
  • Digital Asset Management
  • Digital Certificates
  • Docker
  • Drupal
  • emulator
  • Encryption Tools
  • Endpoint Security Tools
  • Error
  • facebook
  • Firewalls
  • Flutter
  • git
  • GITHUB
  • Google Antigravity
  • Google play console
  • Google reCAPTCHA
  • Gradle
  • Guest posting
  • health and fitness
  • IDE
  • Identity and Access Management
  • Incident Response
  • Instagram
  • Intrusion Detection and Prevention Systems
  • jobs
  • Joomla
  • Keycloak
  • Laravel
  • Law News
  • Lawyer Discussion
  • Legal Advice
  • Linkedin
  • Linkedin Api
  • Linux
  • Livewire
  • Medical Tourism
  • MlOps
  • MobaXterm
  • Mobile Device Management
  • Multi-Factor Authentication
  • MySql
  • Network Traffic Analysis tools
  • Paytm
  • Penetration Testing
  • php
  • PHPMyAdmin
  • Pinterest Api
  • Quora
  • SAST
  • SecOps
  • Secure File Transfer Protocol
  • Security Analytics Tools
  • Security Auditing Tools
  • Security Information and Event Management
  • Seo
  • Server Management Tools
  • Single Sign-On
  • Site Reliability Engineering
  • soft 404
  • software
  • SuiteCRM
  • SysOps
  • Threat Model
  • Twitter
  • Twitter Api
  • ubuntu
  • Uncategorized
  • Virtual Host
  • Virtual Private Networks
  • VPNs
  • Vulnerability Assessment Tools
  • Web Application Firewalls
  • Windows Processor
  • Wordpress
  • WSL (Windows Subsystem for Linux)
  • X.com
  • Xampp
  • Youtube
©2026 DevSecOps Now!!! | WordPress Theme: EcoCoded
wpDiscuz