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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:13:07+00:00 2026-06-10T13:13:07+00:00

For the below files and folder structure beta folder1 folder2 folder3 file1.php file2.php I

  • 0

For the below files and folder structure

beta
   folder1
   folder2
   folder3
   file1.php
   file2.php

I need to restrict access to all files and folders with the exception of folder2 and file2.php. only.

My .htaccess file currently looks like this:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !/folder2%$
RewriteCond %{REQUEST_URI} !/file2.php
RewriteRule $ /beta/file2.php [R=302,L]

The above does work in one system, but not from other system.

Can you point out what i am doing wrong here?

  • 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-10T13:13:09+00:00Added an answer on June 10, 2026 at 1:13 pm

    Try changing your rules around so that you let the 2 folders pass through then redirect everything to file2:

    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /beta/
    RewriteRule ^file2\.php - [L]
    RewriteRule ^folder2 - [L]
    RewriteRule ^ file2.php [L,R=302]
    

    The error you were getting is probably from the % that you had in your condition.

    If you want to outright forbid access to anything else, you can change the last rule to:

    RewriteRule ^ - [L,F]
    

    If you dont mind can you please explain each line ?

    The RewriteBase directive lets the rewrite engine know that relative paths have a URI-base of /beta/. So all of the files/pathnames that don’t start with a / will automatically have that base.

    The next two rules simply matches against the URI and does a “pass through” using the - character, which means, “don’t do anything”. So when you request /folder2 or /file2.php, the rewrite engine does nothing and lets the request through as if nothing happened. But if the request is anything else, the first 2 rules won’t match and the last rule will match because the regex is ^, which matches everything. The target of that rule redirects everything to /beta/file2.php (because of the base).

    The forbidden rule with the F flag in the square brackets is the same thing, If the request isn’t for the folder2 or file2.php, then that rule will match it (^) and it passes it through (-) but the F flag makes it return a “403 Forbidden” instead of serving whatever the request was for.

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

Sidebar

Related Questions

I have the folder structure like below resources/folder1 , /folder2 , /folder3 Now I
The script below should open all the files inside the folder 'pruebaba' recursively but
I have a folder structure, as shown below: I need to create a bash
I'd like to ignore all files below and in a folder except a specific
When there is no files inside the folder the below script goes inside the
I have removed all header files within the below path due to numerous errors
I hope to list all files in document directory using codes below for(NSString *path
This code below allows me to find the word error in all my files
I am using PHP and I need to script something like below: I have
How to copy the folder structure and files into the destination using a Windows

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.