将图像 URL 重定向到新目录
Redirect image URLs to new directories
我正在将网站迁移到新软件,需要将旧图像 URL 重定向到新目录结构。这是我需要重定向的那种模式:
http://domain.com/galleries/directory1/*.gif > https://i.domain.com/galleries/1/big/*.gif
http://domain.com/galleries/directory2/*.gif > https://i.domain.com/galleries/2/big/*.gif
http://domain.com/galleries/directory3/*.gif > https://i.domain.com/galleries/3/big/*.gif
http://domain.com/galleries/directory4/*.gif > https://i.domain.com/galleries/4/big/*.gif
and so on
And also:
http://domain.com/upload/*year*/*month*/*day*/*.gif > https://i.domain.com/galleries/*year*/big/*.gif
任何关于使用什么 htaccess 规则的帮助将不胜感激。谢谢
您可以在 DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?(domain\.com)$ [NC]
RewriteRule ^(galleries)/directory(\d+)/(.+?\.gif)$ http://i.%1///big/ [L,NC,R=301]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(domain\.com)$ [NC]
RewriteRule ^upload/(\d+)/\d+/\d+/(.+?\.gif)$ http://i.%1/galleries//big/ [L,NC,R=301]
下面应该可以解决问题。但是,请注意上传的文件名中的冲突,因为问题没有在目标 url.
中指定不同的月份和日期
RewriteEngine on
RewriteRule ^upload/([0-9]*)/[0-9]*/[0-9]*/(.*.gif)$ "https://i.domain.com/galleries//big/"
RedirectMatch "^/galleries/directory(.)/(.*\.gif)$" "https://i.domain.com/galleries//big/"
我正在将网站迁移到新软件,需要将旧图像 URL 重定向到新目录结构。这是我需要重定向的那种模式:
http://domain.com/galleries/directory1/*.gif > https://i.domain.com/galleries/1/big/*.gif
http://domain.com/galleries/directory2/*.gif > https://i.domain.com/galleries/2/big/*.gif
http://domain.com/galleries/directory3/*.gif > https://i.domain.com/galleries/3/big/*.gif
http://domain.com/galleries/directory4/*.gif > https://i.domain.com/galleries/4/big/*.gif
and so on
And also:
http://domain.com/upload/*year*/*month*/*day*/*.gif > https://i.domain.com/galleries/*year*/big/*.gif
任何关于使用什么 htaccess 规则的帮助将不胜感激。谢谢
您可以在 DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?(domain\.com)$ [NC]
RewriteRule ^(galleries)/directory(\d+)/(.+?\.gif)$ http://i.%1///big/ [L,NC,R=301]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(domain\.com)$ [NC]
RewriteRule ^upload/(\d+)/\d+/\d+/(.+?\.gif)$ http://i.%1/galleries//big/ [L,NC,R=301]
下面应该可以解决问题。但是,请注意上传的文件名中的冲突,因为问题没有在目标 url.
中指定不同的月份和日期 RewriteEngine on
RewriteRule ^upload/([0-9]*)/[0-9]*/[0-9]*/(.*.gif)$ "https://i.domain.com/galleries//big/"
RedirectMatch "^/galleries/directory(.)/(.*\.gif)$" "https://i.domain.com/galleries//big/"