【问题标题】:htaccess redirect to url parameterhtaccess 重定向到 url 参数
【发布时间】:2017-02-01 09:44:38
【问题描述】:

是否可以使用 htaccess 重定向,来自

http://example.com/redirect.php?url=http%3A%2F%2Fanother.com%2Fsmiley.gif

到url参数,

http://another.com/smiley.gif

请指教。

【问题讨论】:

    标签: .htaccess redirect mod-rewrite


    【解决方案1】:

    你可以用这个:

    RewriteEngine on
    
    RewriteCond %{THE_REQUEST} /redirect\.php\?url=.+([^/]+\.gif)\s [NC]
    RewriteRule ^ http://another.com/%1? [NE,L,R]
    

    这会将 /redirect.php?url=foobar/foobar.gif 重定向到 http://another.com/foobar.gif

    【讨论】:

    • 谢谢@starkeen。但是,实际上我的问题与stackoverflow.com/questions/7246497/… 类似。它没有解决我的问题。
    • @kun “它没有解决我的问题”是什么意思?它会将 url 重定向到错误的目的地还是它到底有什么问题?
    • @starken 参数“url=" 包含 url,而不是路径作为您的示例。它是编码的,而且不仅仅是另一个.com。因此,使用您的脚本,它会重定向到http://another.com/http%3A%2F%2Fanother.com%2Fsmiley.gif。我想要的是重定向到http://another.com/smiley.gifhttp://bnother.com/image.jpg
    • @Kun 我在规则中添加了一个 NE 禁止转义标志。请尝试更新后的规则,让我知道它是如何工作的。
    猜你喜欢
    • 1970-01-01
    • 2014-08-10
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多