0

I want to hide a specific content of a text file. Let's say we have a file named (test.txt) and the content of the file is :

data1
data2
data3

the (test.txt) file can be accessible by visiting http://example.com/test.txt. What i want to do is to hide the LINE:3. so when the file is requested it will show only:

data1
data2

what i normally do under apache server is I create a (.htaccess) file and put this following content inside it :

Options -Indexes +FollowSymLinks -MultiViews
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-r
RewriteRule ^(.?)ads\.(.?) somehiddenfolder/hide.php [NC,L]

and i create a hide.php file somewhere inside the server with the following code :

<?php
echo file_get_contents("../../test.txt")."\n";if(!strpos(strtolower($_SERVER['HTTP_USER_AGENT']),"my-user-agent")){die();}?>
data3

now what will happen is (data3) will only be printed if the user agent is corresponding to the hide.php

MyQuestion:

Is there a workaround under NGINX server ? because .htaccess doesn't work !

Any help will be appreciated. Thanks.

X-HAT
  • 33
  • 1
  • 6
  • I'm confused … do you want to remove single lines from your file (first part of your question) or block certain user agents from accessing specific paths (second part of your question)? – knittl May 21 '21 at 17:41
  • Does this answer your question? [How to block a specific user agent in nginx config](https://stackoverflow.com/questions/22144092/how-to-block-a-specific-user-agent-in-nginx-config) – knittl May 21 '21 at 17:50
  • i don't want to remove, but to hide a single line from the text file ! – X-HAT May 21 '21 at 20:59
  • You are not hiding a line from your text file. Instead, you are appending an additional line `data3` to the server response with your PHP script if the `User-Agent` string does not contain `my-user-agent` substring. Your `^(.?)ads\.(.?)` regex has nothing to do with the `/test.txt` URI. – Ivan Shatsky May 24 '21 at 13:06

0 Answers0