htaccess的301重定向整个目录重定向、目录、htaccess

2023-09-02 11:27:18 作者:余生.

迁移TA大型静态网站字preSS(以及重构)后,我有一个固定链接结构不同于原来的目录结构,但新职位蛞蝓是一样的原始文件名。另外值得一提的是,固定链接结构模仿旧的文件路径的文件扩展名。

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.

例如:

曾经是(静态目录)

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

现在(字preSS固定链接结构)

is now (wordpress permalink structure)

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

我的提问:有没有一个简单的htaccess重写规则可以重定向从/path/to/file/(file.htm游客)到/new/path/to/(file.htm) ,而无需创建一个重定向为每个文件?

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?

推荐答案

启用mod_alias就更简单了:

Using mod_alias is even easier:

Redirect 301 /old /new

但如果你有重写规则在htaccess文件已经,那么你需要坚持使用mod_rewrite:

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]