Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
Rewrite requests to directory with htaccess to 404 error

I would like to rewrite requests to directory secret (http://example.com/secret) with .htaccess file to show always 404 Not Found error. I'm using Apache 2.4.

It should work for those cases:

  • /secret/treasure.php (all files and directories in that folder)
  • /secret
  • /secret/
  • /secret?42
  • /secret/?23
  • /secret/.php → should result in 404 Not Found
  • /secret/.htaccess → should result in 404 Not Found

My .htaccess rules block everything except the last two cases (I'm getting 403 error, but it should be 404):

Options -Indexes
RewriteEngine On
RewriteRule ^secret.*$ - [R=404,L]

I would like to rewrite requests /secret/.php and /secret/.htaccess to "404 Not Found error".


UPDATE: This is a bit hacky but seems to block everything

Options -Indexes
RewriteEngine On
RewriteRule ^secret.*$ - [R=404,L]

RewriteRule ^404_error$ - [R=404,L]

<FilesMatch "^\.">
    order allow,deny

    # 403 error
    deny from all

    # Rewrite 403 error to 404 error
    # Must be an absolute path
    ErrorDocument 403 /404_error
</FilesMatch>
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!