htaccess 301 redirect entire directory

12,331

Using mod_alias is even easier:

Redirect 301 /old /new

But if you have rewrite rules in your htaccess file already, then you need to stick with using mod_rewrite:

RewriteRule ^old/(.*)$ /new/$1 [L,R=301]
Share:
12,331
psorensen
Author by

psorensen

Updated on June 05, 2022

Comments

  • psorensen
    psorensen almost 2 years

    After migrating ta large static site to wordpress (as well as a reconstruction), I have a permalink structure that differs from the original directory structure, yet the new post slugs are the same as the original filenames. It's also worth mentioning that the permalink structure mimics the file extension of the old file path.

    For example:

    what was once (static directory)

    www.example.com/old/path/file.htm
    

    is now (wordpress permalink structure)

    www.example.com/new/path/file.htm (note: permalink structure mimics the .htm extension)
    

    My question: Is there a simple htaccess rewrite rule that can redirect visitors from /path/to/file/(file.htm) to /new/path/to/(file.htm), without having to create a redirect for each file?