【问题标题】:redirect to new type of url and remove parts of the url with exception重定向到新类型的 url 并删除部分 url 异常
【发布时间】:2015-05-29 21:42:13
【问题描述】:

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

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

http://www.example.com/VIEW-what-ever-dynamic-url-that-changes-RESOLUTION.html

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

将重定向到:

http://example.com/wp-content/show-image.php?path=http://example.com/wp-content/uploads/what-ever-dynamic-url-that-changes-RESOLUTION.jpg

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

因此,如果 RESOLUTION 为 -1400x1050,那么在新链接上也是如此。

http://www.example.com/VIEW-what-ever-dynamic-url-that-changes-1400x1050.html

http://example.com/wp-content/show-image.php?path=http://example.com/wp-content/uploads/what-ever-dynamic-url-that-changes-1400x1050.jpg

例外:

http://www.example.com/VIEW-what-ever-dynamic-url-that-changes-RESOLUTION.html

如果“-RESOLUTION”(如果以“-other”或“-normal”结尾,请将其从网址中删除

示例:

http://www.example.com/VIEW-what-ever-dynamic-url-that-changes-other.html

将重定向到

http://example.com/wp-content/show-image.php?path=http://example.com/wp-content/uploads/what-ever-dynamic-url-that-changes.jpg

http://www.example.com/VIEW-what-ever-dynamic-url-that-changes-normal.html
will

重定向到

http://example.com/wp-content/show-image.php?path=http://example.com/wp-content/uploads/what-ever-dynamic-url-that-changes.jpg

直到现在我都有这个,但只有具有“example.com/view-”的 url 需要重定向到该 url,而不是全部。也许你能指出我正确的方向?

RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourwebsite\.com$ [NC]

RewriteRule ^/(.*)-other.html$ http://example.com/wp-content/show-image.php?path=http://example.com/wp-content/uploads/$1.jpg [R=301,L]
RewriteRule ^/(.*)-normal.html$ http://example.com/wp-content/show-image.php?path=http://example.com/wp-content/uploads/$1.jpg [R=301,L]

【问题讨论】:

    标签: regex .htaccess mod-rewrite redirect url-redirection


    【解决方案1】:

    试试这个 .htaccess:

    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]
    

    【讨论】:

    • 这似乎可以胜任!非常感谢你,你是生命的救星
    猜你喜欢
    • 1970-01-01
    • 2013-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-01
    相关资源
    最近更新 更多