Want to restrict access to resources - tried so many variations with chat gpt - but it kept cutting off resources the page needs. URL, svg, etc…
Any simple way to do this?
Thanx
-Mike
Want to restrict access to resources - tried so many variations with chat gpt - but it kept cutting off resources the page needs. URL, svg, etc…
Any simple way to do this?
Thanx
-Mike
You will need to modify your prompt most likely. This is the prompt I used and the response I got. You will need to fill in the missing info it asks for. I used Chat GPT.
Prompt:
I need an .htaccess file that restricts direct crawling and public access to the resource folder but allows the html and javascript to access the resource folder as needed to print the pages when called for. Do you need any additional information to complete this task?
Response:
Yes, I need just a little more detail to ensure the .htaccess
rules work correctly for your setup:
What is the name and path of the resource folder? (e.g., /resources/
or /assets/resources/
)
Are the HTML and JavaScript files served from the same domain as the resource folder?
What type of resources are in the folder? (e.g., images, PDFs, JSON, etc.)
How does the HTML/JavaScript access the resource folder? (AJAX/fetch, <img>
, <link>
, etc.)
Once I have that, I can create a .htaccess
file that:
Blocks crawlers and direct browser access
Allows access when requests are made via your HTML/JS on your site
@elementsbot can you help @MichaelDroste ?
spent another couple of hours.. this seems to work didn’t look at all 100+ pages of trumpetstudio.com
This is UNIVERSAL CODE and will protect anyone’s resource folder - I’m posting so that it might help others..
RewriteEngine On
RewriteCond %{HTTP_REFERER} !=“”
RewriteCond %{HTTP_REFERER} !%{HTTP_HOST} [NC]
RewriteCond %{HTTP_REFERER} !^https?://(www.)?youtube.com/ [NC]
RewriteCond %{HTTP_REFERER} !^https?://(www.)?google.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$ [OR]
RewriteCond %{HTTP_REFERER} ^https?://(.*.)?%{HTTP_HOST} [NC]
RewriteRule .(mp3|mp4|pdf|midi|wav)$ - [F,L]
was getting 403 forbidden errors again here is the revised code to fix it - allows http or https variants
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^https?://([a-z0-9-]+.)trumpetstudio.com [NC]
RewriteRule . - [L]
RewriteCond %{HTTP_REFERER} ^$ [OR]
RewriteCond %{HTTP_REFERER} ^https?://(www.)?(youtube|google).com/ [NC]
RewriteRule .* - [L]
RewriteRule .(mp3|mp4|pdf|midi|wav)$ - [F,L]