A 301 redirect permanently sends visitors and search engines to the new address. Set up well, it keeps the value of old links; set up badly, it causes redirect loops or broken pages.
This guide is for Apache-based hosting: HTTP to HTTPS, www to non-www, a single page and a full domain change. Always check first which web server your hosting uses.
Which redirect should you choose?
| Code | Meaning | When to use it |
|---|---|---|
| 301 | Moved permanently | Switching to HTTPS, domain or URL migration. |
| 302 | Found (temporary) | A temporary maintenance or campaign page. |
| 308 | Permanent redirect preserving the method | When the request method (for example POST) must be preserved. |
Before you touch anything
- Make a copy of the current .htaccess file.
- Check that your hosting is Apache-based or compatible; Nginx does not read .htaccess.
- Test in a private window and with curl, because browsers cache 301 redirects.
HTTP → HTTPS
This rule permanently sends every unencrypted request to the HTTPS version, keeping the original path.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]www → non-www (canonical host)
Choose one canonical version and redirect the other to it. Replace pelda.hu with your own domain.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.pelda\.hu$ [NC]
RewriteRule ^ https://pelda.hu%{REQUEST_URI} [L,R=301]Moving a single page or folder
You can send a single old address to its new location with the simple Redirect directive. Give the full address as the target.
Redirect 301 /regi-oldal/ https://pelda.hu/uj-oldal/A full domain change
On the old domain’s hosting, in .htaccess, redirect every address to the same path on the new domain.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?regi-pelda\.hu$ [NC]
RewriteRule ^(.*)$ https://uj-pelda.hu/$1 [L,R=301]WordPress and rule order
On WordPress, place your own rules above the # BEGIN WordPress block so WordPress does not overwrite them and the redirect runs before the general rewrite. If you also use a redirect plugin, do not duplicate rules.
Verification and troubleshooting
- Look for a “301” status code and the correct Location header in the response.
- Check that you reach the final address in one hop; chained redirects slow things down.
- Update internal links, the canonical address and the sitemap to the new address.
| Problem | Likely cause |
|---|---|
| ERR_TOO_MANY_REDIRECTS | Conflicting rules or an HTTPS check behind a proxy. |
| 500 error after the change | A syntax error in .htaccess; restore the copy. |
| Nothing happens | The server does not read .htaccess, or the browser cache interferes. |
curl -I http://pelda.hu/regi-oldal/


