When decommissioning a website, simply placing a "nobody home" page at the root isn't enough. Requests to old URLs or non-existent pages still result in 404 errors. The key is implementing a comprehensive wildcard redirect that captures all traffic - whether to existing pages, deleted pages, or non-existent paths.
The attempted redirect:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.example.com/ [L,R=301,NE]
Only handles HTTP-to-HTTPS redirection. It doesn't catch requests that are already HTTPS or address path redirection. Let's examine the complete solution.
Here's the full implementation that works in shared hosting environments:
RewriteEngine On
# First handle HTTP to HTTPS redirect
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Then redirect all paths to root
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ / [L,R=301]
1. HTTPS Enforcement: The first rule ensures all traffic uses HTTPS
2. Wildcard Redirect: The second rule catches any path request (except the root itself) and redirects to root
3. 301 Status: Permanent redirect helps with SEO and browser caching
For sites with complex legacy requirements:
# Preserve query strings in redirects
RewriteCond %{QUERY_STRING} .+
RewriteRule ^(.*)$ /? [L,R=301]
# Exclude specific paths (e.g., for maintenance tools)
RewriteCond %{REQUEST_URI} !^/(server-status|phpinfo)
RewriteRule ^(.*)$ / [L,R=301]
Use these curl commands to verify:
curl -I http://example.com/oldpage.html
curl -I https://example.com/nonexistent
curl -I http://example.com/deep/path/with?query=string
All should return 301 status with Location: header pointing to your root page.
When decommissioning a website, it's common to replace all existing content with a single landing page. However, many developers struggle with catching all incoming requests - including those for non-existent pages or subdirectories. The standard 301 redirect approach often misses edge cases, particularly in shared hosting environments where server configuration access is limited.
Here's the proper way to implement full-site redirection:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/ [L,R=301]
This solution handles several critical scenarios:
# Handles HTTP to HTTPS redirect first
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# Then catches all paths (including missing files)
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ / [R=301,L]
Problem: 404 errors still appearing for non-existent pages
Fix: The redirect rules must come before any existing rewrite rules that might be processing 404s
Problem: Infinite redirect loops
Fix: Add exclusion for the target page:
RewriteCond %{REQUEST_URI} !^/$
For sites with complex legacy structures, consider these enhancements:
# Preserve query strings
RewriteCond %{QUERY_STRING} .+
RewriteRule ^(.*)$ /? [R=301,L]
# Handle subdomains
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.example.com/ [L,R=301]
Always verify with tools like:
curl -I http://example.com/old-page.html
curl -I https://example.com/non-existent-file.pdf
The response should show HTTP/1.1 301 Moved Permanently in all cases.