Put redirect rules near the top of public_html/.htaccess, above any # BEGIN WordPress block. Test each in a private window, since browsers cache 301s.
One page to another
Redirect 301 /old-page.html https://yourdomain.co.uk/new-page/
A whole folder, keeping the rest of the path
RedirectMatch 301 ^/blog/(.*)$ https://yourdomain.co.uk/news/$1
Old domain to new domain
In the old domain’s .htaccess (on hosting that still serves it):
RewriteEngine On
RewriteRule ^(.*)$ https://newdomain.co.uk/$1 [L,R=301]
Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
HTTPS and non-www in one step
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://yourdomain.co.uk%{REQUEST_URI} [L,R=301]
HTTPS and www in one step
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.yourdomain.co.uk%{REQUEST_URI} [L,R=301]
Remove .html from URLs
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
Avoiding problems
- Combine HTTPS and www into one redirect, not two chained ones.
- Don’t also force HTTPS in a plugin or Cloudflare setting. “Too many redirects” and HTTPS redirect loops
- Use
302while testing, then change to301once correct.
New to Traxio? The PHP hosting page lists the PHP versions, database and tools every account gets, free for the first 30 days.