我正在将我的网站迁移到新软件,需要将旧图像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规则的任何帮助都将非常感激。谢谢
答案 0 :(得分:0)
您可以在DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?(domain\.com)$ [NC]
RewriteRule ^(galleries)/directory(\d+)/(.+?\.gif)$ http://i.%1/$1/$2/big/$3 [L,NC,R=301]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(domain\.com)$ [NC]
RewriteRule ^upload/(\d+)/\d+/\d+/(.+?\.gif)$ http://i.%1/galleries/$1/big/$2 [L,NC,R=301]
答案 1 :(得分:0)
以下应该可以解决问题。但是,请注意上传文件名中的冲突,因为问题并未在目标网址中指定不同的月份和日期。
RewriteEngine on
RewriteRule ^upload/([0-9]*)/[0-9]*/[0-9]*/(.*.gif)$ "https://i.domain.com/galleries/$1/big/$2"
RedirectMatch "^/galleries/directory(.)/(.*\.gif)$" "https://i.domain.com/galleries/$1/big/$2"