Get a free website with any plan

See how
CPANEL

Creating 301 redirects in .htaccess

Last updated

IN SHORT

Flashcloud cPanel hosting allows permanent URL redirection using mod_rewrite rules inside your site's .htaccess file. Adding a 301 RewriteRule directly below RewriteEngine On permanently forwards visitors and passes search engine ranking signals to the new destination. Always place specific redirect rules above general ones to prevent early matching.

A 301 redirect in .htaccess uses mod_rewrite to send visitors and search engines from one URL to another permanently. Add this to the top of your site's .htaccess file, right after RewriteEngine On:

RewriteEngine On
RewriteRule ^old-page$ /new-page [L,R=301]

This is the manual version of what the portal's redirect tool does for you. If you just need to point one URL at another, use Services → your hosting → Domain Redirects instead: it writes the .htaccess entry for you, no file editing required. See Redirecting URLs on your site for the full walkthrough of that tool, including when to use 301 vs 302. This article is for the cases the portal tool doesn't cover: pattern matching, query strings, and conditional logic.

Where to edit .htaccess

Log into cPanel and open File Manager, or connect over FTP with an FTP account from the portal. The file lives in your domain's document root (usually public_html, or the addon domain's folder if you're redirecting a secondary site). It's a hidden (dot) file, so turn on showing hidden files in File Manager if you don't see it.

Back up the file before editing it. A broken mod_rewrite rule can 500 your entire site, and it's much faster to restore a copy than to debug syntax under pressure.

301 vs 302

R=301 tells browsers and search engines the move is permanent. Google transfers ranking signals from the old URL to the new one and eventually drops the old URL from its index. Use 301 for anything permanent: renamed pages, restructured URLs, retired products.

R=302 (temporary) keeps the old URL indexed and doesn't transfer ranking. Reserve it for genuinely temporary situations, like a maintenance page or a short-lived campaign redirect. If you're not sure which to use, use 301. A 302 left in place for months is a common, avoidable SEO mistake.

Rules for common patterns

Redirect one path to another, preserving nothing:

RewriteRule ^old-page$ /new-page [L,R=301]

Redirect a whole folder to a new folder, keeping the rest of the path intact:

RewriteRule ^blog/(.*)$ /articles/$1 [L,R=301]

Here (.*) captures whatever follows blog/, and $1 reinserts it after /articles/. So blog/my-post becomes articles/my-post.

Redirect a URL only when it has a specific query string:

RewriteCond %{QUERY_STRING} ^id=42$
RewriteRule ^product$ /new-product? [L,R=301]

The trailing ? on the destination strips the original query string so it doesn't get appended again. Drop it if you want the query string carried over.

Redirect based on the requested host, useful when consolidating domains without touching every page:

RewriteCond %{HTTP_HOST} ^olddomain\.com$ [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301]

Order and placement matter

mod_rewrite processes rules top to bottom and stops at the first match when [L] is set. Put specific rules above general ones, or the general rule will catch the request first and the specific rule never runs:

RewriteEngine On

# Specific: must come first
RewriteRule ^old-page-special$ /special-landing [L,R=301]

# General: would otherwise swallow the request above
RewriteRule ^old-page(.*)$ /new-page$1 [L,R=301]

Keep all your redirect rules together near the top of the file, after RewriteEngine On, so the order is easy to audit later. WordPress and other apps often add their own rewrite block further down; don't place redirect rules inside it, since it can get regenerated and wipe your edits.

Testing without guessing

Use curl -I from a terminal to see the actual response instead of trusting how the browser renders it:

curl -I https://yourdomain.com/old-page

Look for HTTP/1.1 301 Moved Permanently and a Location: header pointing at the right destination. Browsers cache 301s aggressively, so if you're testing changes in a normal browser tab, use a private/incognito window or clear the cache between edits, otherwise you'll keep seeing the old result even after fixing the rule.

When to contact support

If a rule change results in a 500 error or a redirect loop and reverting your backup doesn't clear it, open a ticket from Support in the portal or use live chat. A real person will look at the actual file and server logs rather than guess from a rule pasted out of context.

Common questions

Why can't I see my .htaccess file in cPanel?

The file is hidden by default. Open File Manager in cPanel and turn on the setting to show hidden files. The file lives in your site's document root, usually public_html.

Should I use a 301 or 302 redirect?

Use a 301 redirect for permanent changes like renamed pages and domain moves. It transfers search ranking signals to the new URL. A 302 redirect is temporary, does not pass ranking signals, and fits short-term maintenance pages.

Why is my browser still going to the old URL after I changed the rule?

Browsers cache 301 redirects aggressively. Test your redirect in a private or incognito window, or clear your browser cache between edits. You can also run curl -I from a terminal to see the raw server response.

Why did my website start showing a 500 error after editing .htaccess?

A syntax error in a mod_rewrite rule triggers an internal server error. Restore your backup copy of the file immediately to bring the site back up. If reverting the backup fails, open a support ticket or contact live chat in the portal.

CAN'T FIND IT?

Real humans answer fast.

Hosting with us? Open a ticket and a real person replies - no scripts, no upsells. Still choosing a host? The same team is included with every plan, from day one.