Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
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 inpublic_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 be644
, and thecrm
folder should be755
. - Confirm that
mod_rewrite
is enabled on your server. Most cPanel hosts have this enabled by default. - If you have a parent
.htaccess
inpublic_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 insidecrm
and contains anindex.php
orindex.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 inpublic_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.