简体   繁体   English

如何为多个目录创建htaccess重定向

[英]How do I create an htaccess redirect for multiple directories

I have to create a htaccess redirect for multiple image directories within a path to a root level image directory. 我必须为根级映像目录路径中的多个映像目录创建htaccess重定向。 The paths all have a variable within them though, in my case a directory named after a city/state... 尽管路径中都有一个变量,但在我的情况下是以城市/州命名的目录...

We have a number of mini sites within our corp site, each mini site has its own image directory: .../images/u/whatever.jpg 我们的公司站点中有许多微型站点,每个微型站点都有自己的映像目录: .../images/u/whatever.jpg

Examples: 例子:

root/store/local/birmingham-al/images/u/ 根目录/商店/本地/伯明翰-al / images / u /

root/store/local/mongomery-al/images/u/ 根目录/存储/本地/ mongomery-al / images / u /

root/store/local/nashville-tn/images/u/ 根目录/存储/本地/ nashville-tn / images / u /

I need a quick redirect that will tell the server to use the new shared image dir, instead of having images served from each of the /images/u/ 我需要一个快速重定向,该重定向将告诉服务器使用新的共享映像目录,而不是从每个/images/u/

All server requests should redirect image requests to: 所有服务器请求都应将图像请求重定向到:

root/imagecdn 根/ imagecdn

How can I do it so I only effect images in those /images/u/ directories? 我该怎么做,所以我只影响那些/ images / u /目录中的图像?

I suck at regex but I'm certain it can be done. 我很喜欢正则表达式,但是我敢肯定它可以做到。 We need this as a quick fix instead of manually changing 1000+ paths. 我们需要此作为快速解决方案,而不是手动更改1000多个路径。

Does this regexp satisfy your needs? 这个正则表达式可以满足您的需求吗?

/^.*/images/u(.*)$/gm

And the replacement string is root/imagecdn$1 . 替换字符串是root/imagecdn$1

Example

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

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