.htaccess htaccess重定向到url参数

.htaccess htaccess重定向到url参数,.htaccess,redirect,mod-rewrite,.htaccess,Redirect,Mod Rewrite,是否可以使用htaccess从 http://example.com/redirect.php?url=http%3A%2F%2Fanother.com%2Fsmiley.gif 到url参数 http://another.com/smiley.gif 请提供建议。您可以使用: RewriteEngine on RewriteCond %{THE_REQUEST} /redirect\.php\?url=.+([^/]+\.gif)\s [NC] RewriteRule ^ http://

是否可以使用htaccess从

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

http://another.com/smiley.gif
请提供建议。

您可以使用:

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

,谢谢@starkeen。但是,实际上我的问题与此类似。它没有解决我的问题。@kun你说的“它没有解决我的问题”是什么意思?它是否将url重定向到错误的目标,或者它到底有什么问题?@starken参数“url=”是包含url,而不是示例中的路径。它是经过编码的,而且不仅仅是另一个网站。因此,使用脚本,它将重定向到
http://another.com/http%3A%2F%2Fanother.com%2Fsmiley.gif
。我想要的是重定向到
http://another.com/smiley.gif
http://bnother.com/image.jpg
@Kun我在规则中添加了一个NE no escape标志。请尝试更新的规则,并让我知道它是如何工作的。