简体   繁体   English

htaccess 301重定向整个目录

[英]htaccess 301 redirect entire directory

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. 在将大型静态站点迁移到wordpress(以及重建)之后,我有一个永久链接结构,它与原始目录结构不同,但新的post slugs与原始文件名相同。 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) 现在(wordpress永久链接结构)

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? 我的问题 :是否有一个简单的htaccess重写规则可以将访问者从/path/to/file/(file.htm)重定向到/new/path/to/(file.htm),而无需为每个文件创建重定向?

Using mod_alias is even easier: 使用mod_alias更容易:

Redirect 301 /old /new

But if you have rewrite rules in your htaccess file already, then you need to stick with using mod_rewrite: 但是如果你已经在你的htaccess文件中重写了规则,那么你需要坚持使用mod_rewrite:

RewriteRule ^old/(.*)$ /new/$1 [L,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM