.htaccess redirects scratchpad
Redirects are a frequent request for me during my working day. Clients moving their sites around, sandbox projects changing domains and other such reasons often call for legacy URLs to be handled with care. While using .htaccess
files slows down your Apache http server, I personally donβt know enough (yet) about httpd
config to use that instead. So enter my .htaccess redirect scratchpad:
General Redirects
Enforce a trailing slash
Problems can occur where links appear in analytics from URLs with both a slash and not. A quick way to rectify is to enforce a trailing slash. Google treats these URLs the same as each other as long as there isnβt duplicate content.
Redirect root domain
This will redirect (301) the entire domain while preserving the path:
Wildcard domain to single URL
Recently had a client close down their site to merge it into another. SEO impact aside I redirected all pages to a specific URL using the following snippet:
WordPress htaccess redirects
You can often still experience redirect loops when using Apache http->https
rewrite behind load balancer / CDN (like Cloudflare). In amongst the other SSL tricks for WordPress using this HTAccess code has worked wonders for me: