Hack Forums
.htaccess - how to proxy all .exe files in a dir? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Webmasters (https://hackforums.net/forumdisplay.php?fid=141)
+---- Forum: Website Construction (https://hackforums.net/forumdisplay.php?fid=50)
+---- Thread: .htaccess - how to proxy all .exe files in a dir? (/showthread.php?tid=4510374)



.htaccess - how to proxy all .exe files in a dir? - 'An0ny - Oct 27, 2014

how could i proxy all .exe files?

example:
i visit http://domain.com/file/randomstring.exe

it will proxiy the file http://domain.com/file/1.exe

any way of doing this with htaccess..?


* - Zasto - Oct 27, 2014

http://corz.org/server/tricks/htaccess.php take a read of this it should help you.


* - 'An0ny - Oct 27, 2014

(Oct 27, 2014 04:45 PM)Zasto Wrote:  http://corz.org/server/tricks/htaccess.php take a read of this it should help you.

I can use google myself, thanks.

Haven't found any with the exact thing I am wanting. I am not too good with htaccess lol


* - Kindfile - Oct 28, 2014

(Oct 27, 2014 04:53 PM)An0ny Wrote:  I can use google myself, thanks.

Haven't found any with the exact thing I am wanting. I am not too good with htaccess lol

Hello An0ny,

I believe the mod_rewrite module is what you are looking for. For documentation take a look here:
http://httpd.apache.org/docs/trunk/rewrite/remapping.html

Code
RewriteEngine  on
RewriteRule    ^/foo\.html$  /bar.html [PT]

So in your case:
Code
RewriteEngine  on
RewriteRule    ^/randsomstring\.exe$  /1.exe [PT]

You can also use regex to match the file name. For example
Code
RewriteEngine  on
RewriteRule    ^/.*\.exe$  /1.exe [PT]

Should match {anything}.exe and point it towards 1.exe

Hope this helped.

Kind regards


* - c x y k - Oct 28, 2014

It isn't possible to count the number of files, which I assume is what you want (1,2,3,4,etc.).


* - Squito - Oct 28, 2014

.htaccess:
Code
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*).exe$ file.php?file=$1 [NC,L]

file.php:
PHP Code

<?PHP
header
("Content-type: application/octet-stream");
if(isset(
$_GET['file']))
{
    if(
$_GET['file']=="xyz")
    {
        
readfile("abc.exe");
    }
}
?>
Put the .htaccess and the file.php into the directory where you keep the exe files and it will work.


* - 'An0ny - Oct 28, 2014

(Oct 28, 2014 06:34 AM)Kindfile Wrote:  Hello An0ny,

I believe the mod_rewrite module is what you are looking for. For documentation take a look here:
http://httpd.apache.org/docs/trunk/rewrite/remapping.html

Code
RewriteEngine  on
RewriteRule    ^/foo\.html$  /bar.html [PT]

So in your case:
Code
RewriteEngine  on
RewriteRule    ^/randsomstring\.exe$  /1.exe [PT]

You can also use regex to match the file name. For example
Code
RewriteEngine  on
RewriteRule    ^/.*\.exe$  /1.exe [PT]

Should match {anything}.exe and point it towards 1.exe

Hope this helped.

Kind regards

Thanks - exactly what I were looking for 🤝