Mod Rewrite and pass URL as parameter

I have small problems with mod rebuilding. My friend writes a script that allows you to upload images.

What we want to do is allow the user to add the domain name to the direct link, and the script will extract the image from the provided URL.

For example, if the image is on the page http://www.test.com/image.jpg , adding domain.com /http://www.test.com/image.jpg will allow the script to get this url (test.com), to get the desired image.

EDIT: HTTP is in front of the url because I don't want the user to have to manually remove HTTP. They see the image in their browser, before it adds "domain.com", http and that's it, and the script extracts this image and saves it on our server.

The rule that I use:

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

this matches the urls correctly, but the colon in http: // is causing problems.

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

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

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

: , , , URL-, $_GET ['url'] , , 403.

, ? ?

.

+2
4

, , . , mod_rewrite.

, Apache Windows, ​​WONTFIX.

. fooobar.com/questions/1614407/...

, , . !

+2

urlencode() php

+1

, (, URL- )

, , -, , . http://your.sharing.service , . mod_rewrite script, , ( ) .

​​, , URL- - script (, http://my.service.com/upload?url=...).

+1
source

The problem is in your regex ...

Try:

^((http|https)+[\:\/\/\w\.]+(jpg|png|gif))$
0
source

Source: https://habr.com/ru/post/1614402/


All Articles