简体   繁体   English

将所有文件移动到一个文件夹中,然后htaccess重定向到它们?

[英]Move All Files in One Folder and htaccess Redirect to Them?

I have a bunch of old static html sites. 我有一堆旧的静态html网站。 I want to install wordpress in the root on every site, but still keep the old pages. 我想在每个站点的根目录中安装wordpress,但仍保留旧页面。 So I want to somehow automate this process for every single file: 因此,我想以某种方式针对每个文件自动执行此过程:

  1. Group and Move all files into a single folder (all html into \\files, all media into files\\media css into files\\css and so on) 将所有文件分组并移动到一个文件夹中(所有html到\\ files,所有媒体到files \\ media css到files \\ css,依此类推)
  2. Create rules in htaccess to redirect all of the original URLs of those files to their new respective paths in the new folder. 在htaccess中创建规则,以将那些文件的所有原始URL重定向到新文件夹中的新路径。 Example: 例:

website.com/category1/file1.html MOVED to website.com/files/file1.html website.com/category1/file1.html移动到website.com/files/file1.html

.htaccess rule: .htaccess规则:

RewriteRule ^category1/file1.html$ files/file1.html [L]

I need to do this for 30+ sites with many files. 我需要对30个以上包含许多文件的网站进行此操作。 Is there a way to somehow automate this process? 有没有办法使该过程自动化?

This should work: 这应该工作:

RewriteRule ^category1/(.*)$ files/(.*) [R=301,L]

That will redirect website.com/category1/file1.html to website.com/files/file1.html . 这将把website.com/category1/file1.html重定向到website.com/files/file1.html

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

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