Is there a .htaccess script that I could put into any subdirectory A without modification, which would catch all requests to files in that subdirectory A as well as deeper subdirectories A/* and rewrite it to subdirectory A? The original browser URL should stay intact and again preferably, I'd like to do this without modifying the .htaccess script.

Example:

domain.com/dir1/dir2            <-- this directory should become the endpoint

domain.com/dir1/dir2/dir3       <-- rewrite (keep browser URL intact) to /dir1/dir2

domain.com/dir1/dir2/dir3/dir4  <-- rewrite (keep browser URL intact) to /dir1/dir2

I have this working with the following script, but this script would need me to update it for any directory I put it in....

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /dir1/dir2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dir1/dir2/ [L]
1

There are 1 best solutions below

0
On

This rule should work for you:

RewriteEngine On    
RewriteRule . /dir1/dir2/ [L]

That is match any file/directory in /dir1/dir2/ other than just /dir1/dir2/ and rewrite to base of /dir1/dir2/.