重定向到新类型的 URL 并删除 URL 中的部分异常

重定向到新类型的 URL 并删除 URL 中的部分异常

我需要将旧链接重定向到新链接。新链接会有些不同。

例如这个(我用 capslook 标记了不属于帖子名称的部分)

example.com/VIEW-what-ever-dynamic-url-that-c​​hanges-RESOLUTION.html

(“-RESOLUTION”类似于“-1400x1050”或“-other”等。)

将重定向至:

example.com/wp-content/show-image.php?path=example.com/wp-content/uploads/what-ever-dynamic-url-that-c​​hanges-RESOLUTION.jpg

因此请注意,旧网址中的“view-”消失了,并且“ .html”被替换为“ .jpg”(图像类型)

所以如果分辨率是 -1400x1050,那么在新链接上也会相同。

example.com/VIEW-what-ever-dynamic-url-that-c​​hanges-1400x1050.html

example.com/wp-content/show-image.php?path=example.com/wp-content/uploads/what-ever-dynamic-url-that-c​​hanges-1400x1050.jpg

例外:

example.com/VIEW-what-ever-dynamic-url-that-c​​hanges-RESOLUTION.html 如果“-RESOLUTION”(如果以“-other”或“-normal”结尾),请将其从网址中删除

例子:

example.com/VIEW-what-ever-dynamic-url-that-c​​hanges-other.html 将重定向到

example.com/wp-content/show-image.php?path=example.com/wp-content/uploads/what-ever-dynamic-url-that-c​​hanges.jpg

example.com/VIEW-what-ever-dynamic-url-that-c​​hanges-normal.html 将重定向到

example.com/wp-content/show-image.php?path=example.com/wp-content/uploads/what-ever-dynamic-url-that-c​​hanges.jpg

(链接确实有“http://www“但由于此帖子的链接限制,我无法添加它)

有什么帮助吗?

谢谢

答案1

解决了!

RewriteEngine on

# other or normal URL
RewriteRule ^VIEW-(.+?)-(?:other|normal)\.html$ http://example.com/wp-content/show-image.php?path=http://example.com/wp-content/uploads/$1.jpg [R=302,L,NC]

# resolution URL
RewriteRule ^VIEW-(.+?\d+x\d+)\.html$ http://example.com/wp-content/show-image.php?path=http://example.com/wp-content/uploads/$1.jpg [R=302,L,NC]

相关内容