简体   繁体   English

将目录重定向到Apache上的脚本

[英]Redirecting a Directory to a Script on Apache

So I'm playing with a script that makes it super easy to mirror images off of the web. 因此,我正在使用一个脚本,可以非常轻松地从网络上镜像图像。 The script works great (based off of the old imgred.com source, if you've seen that) problem is, it looks a little clunky when using it. 该脚本很好用(基于旧imgred.com的源代码,如果您已经看到的话),问题是,使用它时看起来有些笨拙。

Currently, in order to use the script, you go to a url like: 当前,为了使用脚本,您可以使用以下网址:

http://mydomain.com/mirror/imgred.php?Image=http://otherdomain.com/image.jpg

What I'd like to do is to be able to go to: 我想做的是能够去:

http://mydomain.com/mirror/http://otherdomain.com/image.jpg

and have it redirect to the former URL, preferably transparent to the user. 并将其重定向到以前的URL,最好对用户透明。

I'm reasonably certain that this can be done via .htaccess with a MOD_REWRITE of some kind, but I'm getting frustrated trying to get that to work. 我可以肯定的是,可以通过.htaccess使用某种MOD_REWRITE来完成此操作,但我对此尝试感到沮丧。

After messing with this myself, I found out that apache collapses any double slash in the URL before the query part into a single slash, and passes the result to mod_rewrite. 在自己弄乱之后,我发现apache将查询部分之前的URL中的任何双斜杠折叠成一个斜杠,并将结果传递给mod_rewrite。 Maybe that was giving you problems? 也许那给你带来了麻烦?

This might work for you (.htaccess in the mirror directory): 这可能对您有用( mirror目录中的.htaccess):

RewriteEngine On
RewriteBase /mirror
RewriteRule ^http(s?):/(.*) imgred.php?Image=http$1://$2 [L]

Don't know if your script accepts https addresses as well, so I included that just to be sure 不知道您的脚本是否也接受https地址,所以我添加了它只是为了确保

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM