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 8611509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:23:40+00:00 2026-06-12T04:23:40+00:00

I want to restrict access to a file or files using .htaccess file. Basically,

  • 0

I want to restrict access to a file or files using .htaccess file. Basically, no one should be able to download file(s) using direct link to the file. However, the file should be accessible from my website.

For instance, say I have a file called Presentation.ppt. I want the visitor to have access to it through my website, but if they try to download it or access it using direct link then the server should reject the request.

Is it possible to do that using .htaccess?

Thank you in advance,

  • 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-12T04:23:41+00:00Added an answer on June 12, 2026 at 4:23 am

    Thank you all for your answers. I have tried all of your suggestions, but I still couldn’t get it working. However, I did come up with a solution that does work.

    Step 1: Disable or turn off Option Indexes on your web server by removing the word indexes leaving everything else the same. In some instances, you may be able to do this using .htaccess file. If you are unable to do this with .htaccess, then you will have to look for httpd.conf file in your server. It is usually located at etc/apache/httpd.conf or etc/httpd/conf/httpd.conf. Once you find it, turn this option off in there.

    Step 2: Create a folder within your webpage folder and call it whatever you want but make sure it is not easily guessable or that it is obvious (i.e. Joe33CompanyOCT2MeBoss). Then, move the files you want to hide or protect from your visitor into this folder.

    Step 3: Within robot.txt file, disallow all bots or crawlers from indexing your folder or the files within this folder by entering, “Disallow yourfoldername.”

    Step 4: Then you will have to create a PHP file using a similar code below. The code below will force download.

            $File1 = 'http://yourwebsite.com/Joe33CompanyOCT2MeBoss/Presentation.ppt';
            header("Content-Disposition: attachment; filename=\"".basename($File1)."\"");
            header("Content-Type: application/force-download");
            ob_end_clean();
            flush();
            readfile($File1);
            exit;
    

    This way direct path to the file is hidden from your visitor and even though they can download the file directly they simply don’t know the actual URL to the file, because force download php code doesn’t reveal the actual path to the file. So, now my visitors to my website has to go through my webpage for downloading this file instead of directly.

    Following stackoverflow questions have been very instrumental in helping me solve my programming issues. Thanks,

    How to Automatically Start a Download in PHP?

    php file force download

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to restrict access of a download only when someone
I want to restrict access to certain web directories in my website using .htaccess
I want to restrict access to parts of my Android application using a pattern
I want to restrict access to all but a few selected files per a
I want to restrict my web app so that .txt files can not be
I want to have users be able to upload .pdf and images and restrict
I have a folder with multiple .aspx pages that I want to restrict access
I want to allow users to download a file, but in order to do
Very simple problem. I have a Delphi application and I want to restrict access
I asked a while ago how to restrict plugins access ( I want to

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.