What a 301 redirect does and where .htaccess sits
A 301 tells the browser and Google that a URL has moved for good. In Apache or LiteSpeed you write it in the .htaccess file in the site's document root, usually public_html, and every request is checked against it before the page loads. One line handles a single page; three lines move a whole domain.
- 301 — permanent. Browsers cache it hard, and search engines pass the old URL's signals to the new one.
- 302 — temporary. Use it while testing, or for a short campaign, never for a real move.
- .htaccess — a hidden text file read per directory. It does nothing on an Nginx server, which ignores the file.
Two directives do the work. Redirect and RedirectMatch come from mod_alias and are simple. RewriteRule comes from mod_rewrite, handles patterns, and is the only option for conditions such as the host name.
Redirect one page with a single Redirect 301 line
For one old URL to one new URL, the short form is enough. Open File Manager, turn on Show Hidden Files, and edit .htaccess in public_html.
- Back up the file first: copy .htaccess to .htaccess.bak in the same folder.
- Add the rule at the top of the file, above any WordPress block: Redirect 301 /old-page/ /new-page/
- For a target on another site, use the full URL: Redirect 301 /old-page/ https://example.com/new-page/
- Save, then open the old URL in a private window. It should land on the new page in one hop.
The first path is local to the site, starting with /, never the full address. The second can be local or a full URL. For a pattern instead of an exact path, use RedirectMatch 301 ^/old-folder/(.*)$ /new-folder/$1, where $1 carries the rest of the path across.
Redirect every URL on an old domain to a new one
A domain move needs the path preserved, so a plain Redirect will not do. Put this in the old domain's .htaccess, which keeps each page's address after the slash:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]
The condition limits the rule to requests for the old host, so the same file cannot loop the new domain back on itself. The $1 in the target is whatever the visitor asked for. The [R=301,L] flags mean send a 301 and stop processing further rules.
Keep the old domain registered and pointed at the same server for at least a year. A redirect only works while the name resolves.
Force HTTPS and choose www or non-www
Google treats example.com and www.example.com as two sites, so pick one and redirect the other. Add HTTPS at the same time, in one rule rather than two, and put it above everything else.
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
That sends http://example.com/about/ and https://example.com/about/ both to https://www.example.com/about/ in one hop. Two separate rules, one for HTTPS and one for www, create a chain of two redirects, which is slower and harder to debug.
If the site already sits behind a proxy or a CDN, %{HTTPS} can read as off even on a secure request. In that case test with curl before you trust the rule, or ask support whether the server passes X-Forwarded-Proto.
Redirect folders, file extensions and query strings
Folder and pattern moves are where RewriteRule earns its place. Each example below assumes RewriteEngine On sits above it.
| What moves | Rule |
|---|---|
| Every file in one folder | RewriteRule ^blog/archives/(.*)$ /newarchives/$1 [R=301,L] |
| All .php URLs to .html | RewriteRule ^(.*)\.php$ /$1.html [R=301,L] |
| Drop the query string | RewriteRule ^old/(.*)$ /new/$1? [R=301,L] |
| Keep the query string | RewriteRule ^old/(.*)$ /new/$1 [R=301,L] |
| Trailing slash added | RewriteRule ^(.*[^/])$ /$1/ [R=301,L] |
The trailing question mark is the one people miss. Without it Apache appends the old query string to the new URL, so a tracking parameter survives a redirect you wanted clean. On Apache 2.4 the [QSD] flag does the same job more explicitly.
Check the redirect, and roll back if the site returns 500
Do not judge a redirect by what the browser shows. Read the status line. From a terminal:
curl -I https://example.com/old-page/
You want HTTP/1.1 301 Moved Permanently and a Location: line with the new URL. A 200 means no rule matched. A 302 means the wrong code. A chain of two 301s shows up as two requests in the browser's Network tab.
| Symptom | Cause and fix |
|---|---|
| 500 Internal Server Error after saving | A syntax error. Rename .htaccess to .htaccess.bak in File Manager; the site returns at once. Fix the line and rename back. |
| "Too many redirects" in the browser | A rule matches its own target. Check that www and HTTPS rules point one way only. |
| Rule has no effect | A typo in the path, a missing leading slash, or the file is in the wrong folder. Confirm it sits in public_html, not above it. |
| Works for you, not for others | The 301 is cached in your browser. Test in a private window or with curl. |
| Rule works, then stops | Another plugin wrote over .htaccess. Re-add the rule above the WordPress block. |
While you test, use a 302. Change it to 301 only when the target is right, because a browser that cached a wrong 301 keeps sending visitors to the wrong page long after you fix the file.
Where the rules go in a WordPress .htaccess file
WordPress writes its own block between # BEGIN WordPress and # END WordPress on every permalink save. Put redirect rules above that block, so they run before the WordPress rewrite, and never inside it.
If a plugin such as Redirection or Rank Math already manages redirects, use one method only. Two systems writing the same file is how a working rule disappears after a settings save. The plugin route for non-coders is covered in the WordPress 301 redirects guide.
On Linux hosting with Apache or LiteSpeed, all of this works from cPanel File Manager. On a cPanel account you also have Domains, then Redirects, which writes the .htaccess line for you when a single page is all you need.
If a rule refuses to take effect and the file looks correct, email support@webji.services with the rule, the old URL and the new one. Support answers 24/7 by email in Hindi and English, and the office phone is not a support line.
Frequently Asked Questions
How do I create a 301 redirect in .htaccess?
Add Redirect 301 /old-page/ /new-page/ to the .htaccess file in public_html, above any WordPress block. Save, then open the old URL in a private window and confirm it lands on the new page in one hop.
How do I redirect a whole site to a new domain?
Use RewriteEngine On, a RewriteCond that matches the old host, and RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]. The $1 keeps each page's path, so old links land on the same page rather than the homepage.
How do I force HTTPS using .htaccess?
Add RewriteCond %{HTTPS} off and RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] near the top of the file. If a proxy or CDN sits in front of the server, test the result with curl, because %{HTTPS} can read as off on a secure request.
How do I redirect one page to another URL?
Use Redirect 301 /old-page/ /new-page/ for a page on the same site, or Redirect 301 /old-page/ https://other-site.com/new-page/ for one elsewhere. Both take effect as soon as the file is saved.
What is the difference between 301 and 302?
A 301 is permanent: browsers cache it and search engines move the old URL's signals to the new one. A 302 is temporary and is not cached the same way. Use 302 while testing and switch to 301 once the target is right.
Why did my .htaccess change break the site with a 500 error?
Apache rejects the whole file when one line is invalid, so a missing space or a bad flag takes every page down. Rename .htaccess to .htaccess.bak in File Manager, fix the line, and rename it back.

