How to Redirect Known Pages and Wildcard for Everything Else with htaccess


I recently worked on a project which needed me to shut down a WordPress blog and migrate it’s content. I had about 20 posts and pages that were going to migrate but everything else was going to be deleted. Since htaccess runs their commands from the top to the bottom, place your known redirects above your catch all redirect.

# redirect the posts and pages that moved - list all known urls below
Redirect 301 /known-path/ https://www.newdomain.com/known-path/

# Redirect old directory and child pages to a new directory name
RewriteRule ^/category/solutions/(.*)$ https://www.newdomain.com/topics/trends/$1 [R=301,NC,L]

# Redirect everything else to the new domain homepage
RedirectMatch 301 ^ https://www.newdomain.com/

 


About the Author

Jacob Lett (Jake) is the founder of Bootstrap Creative, a B2B marketing consultancy specializing in manufacturers and industrial companies. A HubSpot-certified CMS developer, SEO, Answer Engine Optimization (AEO), and RevOps professional, he helps B2B companies improve their websites, search visibility, HubSpot systems, and Google Ads campaigns to generate more qualified leads and RFQs. With over a decade of hands-on experience, he acts as a direct partner for companies seeking measurable ROI from their marketing investment.



Related posts
Category: Code Snippets

Tags: ,

| Read My Editorial Policy

Want to Get Email Updates of New Articles?

Join My Email Newsletter