APACHE · HTACCESS
How to Redirect an Entire Directory with .htaccess
Move a whole set of URLs while keeping the path after the directory name.
If the old URLs begin with /snowman/ and the new URLs should begin with /snowman-games/, put this rule in the site root .htaccess file:
RewriteEngine On
RewriteRule ^snowman/(.*)$ /snowman-games/$1 [R=301,L]The captured part (.*) contains everything after snowman/. The $1 in the destination inserts it after /snowman-games/. For example, /snowman/play/ becomes /snowman-games/play/.
Where to place the rule
Place it near the top of your site root .htaccess, before broad catchall rewrites. Apache's per-directory RewriteRule pattern does not begin with a slash, which is why the pattern starts with snowman/. The destination begins with a slash because it is a path from the website root.
Check the destination
Make sure the equivalent page exists at the new address. A 301 signals a permanent move, so test with a temporary 302 while developing if you expect to revise the rule. Check the directory root and at least one deeper URL, and confirm the redirect reaches the destination in one step.