Mod重写并将URL作为参数传递 [英] Mod Rewrite and passing a URL as parameter

查看:90
本文介绍了Mod重写并将URL作为参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用mod重写时遇到了小麻烦.我的一个朋友正在编写一个脚本,使您可以上传图像.

I am having a small trouble with mod rewrite. A friend of mine is writing a script that allows you to upload images.

我们要做的是允许用户将域名附加到直接的图像链接上,脚本将从提供的URL中检索图像.

What we want to do is allow the user to append a domain name to a direct image link, and the script would retrieve the image from the supplied URL.

例如,如果图像位于: http://www.test.com/image.jpg ,添加 domain.com /http://www.test.com/image.jpg将允许脚本检索该URL(test.com)以获取所需的图像.

For example, if the image is at: http://www.test.com/image.jpg, adding domain.com/http://www.test.com/image.jpg would allow a script to retrieve that url (test.com) to get the image we want.

HTTP位于URL的前面,因为我不希望用户必须手动删除HTTP.他们在浏览器中看到一个图像,并在其之前附加"domain.com",http和all,然后脚本检索该图像并将其存储在我们的服务器上.

HTTP is in front of the URL because I don't want the user to have to remove the HTTP manually. They see an image in their browser, they append "domain.com" before it, http and all and the script retrieves that image and stores it on our server.

我使用的规则是:

RewriteRule ^([\w|.|/]+(jpg|png|gif))$ /upload.php?url=http://$1 [B,L,NC,R=302]

这可以正确匹配URL,但是http://中的冒号会引起问题.

this correctly matches URLs but the colon in http:// causes problems.

如果用户输入:domain.com/www.test.com/image.jpg,则可以使用.

If the user inputs: domain.com/www.test.com/image.jpg, it works.

如果用户输入:domain.com/http://www.test.com/image.jpg,则无法正常工作,我得到了403禁止页面(在Windows上为XAMPP).

If the user inputs: domain.com/http://www.test.com/image.jpg, it doesn't work and I get a 403 forbidden page (XAMPP on Windows).

如果用户输入:domain.com/http//www.test.com/image.jpg,则可以使用(http中没有冒号).

If the user inputs: domain.com/http//www.test.com/image.jpg, it works (no colon in http).

通过工作,我的意思是,如果我在本地对其进行测试,则可以看到我在$ _GET ['url']参数中正确传递的URL,而不是看到错误403.

By working, I mean if I test it locally, I get to see the URL I pass in a $_GET['url'] parameter correctly, instead of seeing an error 403.

能否请您告诉我此规则有什么问题以及如何解决?还是任何其他解决方案可以实现我们想要的行为?

Can you please tell me what is wrong with this rule and how to fix it? Or any alternative solutions to achieve the behavior we want?

谢谢.

推荐答案

好吧,我想我已经找到问题了.它不是正则表达式,也不是mod_rewrite本身.

Well, I think I've found the problem. It wasn't the regex, nor mod_rewrite itself.

因此,这是Windows中Apache中的一个错误,该错误已声明为WONTFIX.

So it's a bug in Apache on Windows that has been declared WONTFIX.

作为参考,请参见此StackOverflow线程:此错误报告

我将发布我发现的内容,并将认为此问题已得到回答.谢谢大家!

I'm posting what I found and will consider this question answered. Thank you all!

这篇关于Mod重写并将URL作为参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆