Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8748837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:35:37+00:00 2026-06-13T12:35:37+00:00

I have a website that has a folder for images. I have two problems:

  • 0

I have a website that has a folder for images.

I have two problems:

  1. I want to disable all script execution in that directory (i.e. no PHP/Perl/Python
    anything.)
  2. There are two php files in my images folder called gradient.php and rgba.php – I do what those to run as per usual.

How do I set up my .htaccess file to do that. Also, rather than placing a new .htaccess in the images directory, is it possible to incorporate these directives in the one in the site root?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:35:38+00:00Added an answer on June 13, 2026 at 12:35 pm

    You can add these rules to the htaccess file in your site root:

    # check if the request is for the images folder
    RewriteCond %{REQUEST_URI} ^/images/
    
    # check that it isn't a request for an image
    RewriteCond %{REQUEST_URI} !\.(jpe?g|png|gif|bmp)$ [NC]
    
    # check that it isn't a request for the 2 ok php files
    RewriteCond %{REQUEST_URI} !^/images/(gradient|rgba)\.php$
    
    # forbid access
    RewriteRule ^ - [L,F]
    

    This should make it so any request for /images/ that doesn’t end with jpg/jpeg/png/gif/bmp (or whatever other extension you want to add to the regular expression) or isn’t gradient.php or rgba.php, will result in a 403 forbidden.


    EDIT:

    I don’t want them to be forbidden, I just want them to not execute – it’s an upload folder, so I basically want it that if someone uploads a JPG that is secretly PHP code that I haven’t detected, that it won’t run

    as long as jpg and other images are mapped to the correct mime/type (via AddType image/jpeg .jpg) then it won’t get handed to the php handler and whatever code is there won’t get executed. If you want to serve all files using the default handler, you need to set AddHandler default-handler php in the htaccess file in your images directory. You’ll then need to move the gradient and rgba files out to some other directory. You can’t selectively set handlers from an htaccess file, though you may be able to use <Location> blocks to set handlers in your vhost config.


    EDIT 2:

    I was wrong, you can use the H flag to set a custom handler using a rule. So in the above rules, instead of [L,F], you can do [L,H=default-handler] so that anything that isn’t an image or gradient.php or rgba.php will get sent to the default-handler (e.g. php files will get sent as-is, and not handled and executed by mod_php).

    So you can just do:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/images/(gradient|rgba)\.php$
    RewriteRule ^ - [L,H=default-handler]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website that has an include folder which contains php templates and
I have been working on a website that has some images that I need
I have ASP.net website. In App_Code folder I have class that has extension methods.
So basically I have website that has names of cities that can be checked
I have a website that has highly granulised access and hence requires many web.config
I have a website that has one database I have also Desktop apps that
I have a website that has products list page and product detail page .
I have a website that has approx 1000 different strings in a mysql database
I have a website that has a relative path to a stylesheet that looks
I have a travel related website that has been online for several years (since

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.