Mod重写并将URL作为参数传递

编程入门 行业动态 更新时间:2024-10-23 13:26:43
本文介绍了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.

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

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

HTTP位于URL的前面,因为我不希望用户必须手动删除HTTP.他们在浏览器中看到一个图像,并在其之前附加"domain",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" 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=$1 [B,L,NC,R=302]

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

this correctly matches URLs but the colon in causes problems.

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

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

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

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

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

If the user inputs: domain/http//www.test/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作为参数传递

本文发布于:2023-11-01 20:22:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550320.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:并将   重写   参数   Mod   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!