Rewrite rules allow you to redirect or modify URLs using Apache’s mod_rewrite module. In cPanel, rewrite rules are usually added to the .htaccess file. Common uses include redirecting pages, creating SEO‑friendly URLs, or forcing HTTPS.
Requirements
Before you begin, ensure:
-
Your hosting account uses Apache
-
mod_rewrite is enabled (this is enabled by default on most cPanel servers)
-
You have access to File Manager in cPanel
Step 1: Log in to cPanel
-
Log in to your cPanel account.
-
Navigate to Files → File Manager.
Step 2: Locate or Create the .htaccess File
-
Open the directory where the rule should apply:
-
Usually public_html/
-
-
If you do not see a
.htaccessfile:-
Click Settings (top-right)
-
Enable Show Hidden Files (Dotfiles)
-
Click Save
-
-
If the file still doesn’t exist:
-
Click + File
-
Name it
.htaccess
-
Step 3: Enable Rewrite Engine
At the top of the .htaccess file, add:
RewriteEngine On
âš ï¸ This line should appear only once per file.
Step 4: Add a Rewrite Rule
Below are common examples you can copy and modify.
Example 1: Redirect One Page to Another
RewriteRule ^old-page\.html$ new-page.html [R=301,L]
Example 2: Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
Example 3: Remove .php from URLs
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)$ $1.php [L]
Example 4: SEO‑Friendly URLs
Convert:
example.com/profile.php?user=john
To:
example.com/profile/john
RewriteRule ^profile/([^/]+)/?$ profile.php?user=$1 [L,QSA]
Step 5: Save and Test
-
Click Save Changes
-
Test the URL in your browser
-
Clear your browser cache if needed
Troubleshooting
-
500 Internal Server Error:
A syntax error may exist in.htaccess. Revert your changes and try again. -
Rule not working:
EnsureRewriteEngine Onis present and rules are placed above other redirects.
Best Practices
-
Always back up
.htaccessbefore editing -
Use 301 redirects for permanent URL changes
-
Keep rules simple and well‑commented
Need Help?
If you are unsure which rewrite rule to use, contact your hosting provider or consult the Apache mod_rewrite documentation.