Reputation: 13729
I need to access files from two directories in the same directory in a browser.
Visually the directories may look like this:
/public_html/www.example.com/xml/
/xml/
/public_html/.htaccess
Important clarification: this setup supports multiple domains.
/public_html/www.example1.com/
/public_html/www.example2.com/
The XML files requested at http://www.example.com/xml/ are located at /public_html/www.example.com/xml/ and if the file does not exist at that server path then I need to check at the /xml/ server path.
Obviously from the browser we'll be accessing the /public_html/xml/ path (e.g. www.example.com/xml/) so let's say we can see a directory index with Apache generated links to all the XML files. I want to be able to also access the files in the /xml/ directory from example.com/xml/.
There is also the issue of files having the exact name being present in both directories. I'd prefer the /public_html/xml/ directory to take precedence so if a user requests www.example.com/xml/1.xml the copy at /public_html/xml/1.xml is displayed instead of /xml/1.xml if possible.
Remember, I want to MERGE access to all the files in both directories to a single directory, I do not want to make files from either directory inaccessible in order to make the files in other directory accessible.
This must be done using the .htaccess file located at /.htaccess beneath.
Upvotes: 1
Views: 1338
Reputation: 16214
Something like that .htaccess in /public_html/xml/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ - [L]
RewriteCond /PhysicalPath2AnotherFolder/%{REQUEST_URI} -f [OR]
RewriteCond /PhysicalPath2AnotherFolder/%{REQUEST_URI} -d
RewriteRule ^(.*)$ /WebPath2AnotherFolder/$1 [L]
ps: PhysicalPath2AnotherFolder should have, but not include, webpath of the original directory in it. Or, of course, it is possible to add additional RewriteCond in order to take only the filename from REQUEST_URI. In that case it would be something like (I did not test it :))..
RewriteCond %{REQUEST_URI} ^/.*?([^\/]+)$
RewriteCond /PhysicalPath2AnotherFolder/%1 -f [OR]
RewriteCond /PhysicalPath2AnotherFolder/%1 -d
RewriteRule ^(.*)$ /WebPath2AnotherFolder/$1 [L]
Upvotes: 2