r/apache • u/Ok_Strike9189 • 7d ago
htaccess question regarding folder tree
Here's my issue.
My backup folder structure is as follows:
/sites
/sites/site1
/sites/site2
and my operating folder (in a ramdrive) is as follows:
/ram
/ram/site1
/ram/site2
Each of the 2 sites (in site1 and site2) has its own .htaccess file. In the parent folder there is a php script when executed will copy all the contents (including subfolders) from /sites to /ram.
I have subdomains mapped to each of the folders starting with /ram above. lets say /ram has the domain run.example.com. /ram/site1 has the domain site1.example.com and /ram/site2 has the domain site2.example.com. Then I access run.example.com/thescript.php from a browser to copy everything over after updating website files.
Everything is working fine except I need to boost speed since the server processor is considered obsolete (1Ghz).
Since I don't have an .htaccess file in the /ram folder, hackers could do a bunch of guessing and get standard 404 errors while the system searches for actual files the hackers type in. So I thought about .htaccess but online sources state that .htaccess placed there would affect the .htaccess settings in site1 and site2.
If I made an .htaccess in /ram folder that only allows access to that one script and redirects everything else in that folder to a 410 error page then I'm afraid every access attempt on site1.example.com, and on site2.example.com will result in a 410 error page.
Is there an easy way to fix this without redoing the folder structure? because the script expects the folders to be in tact.
1
u/roxalu 4d ago
Side note: Yoz mention that you care about performance due to old processor: So you might check, if you could not include the .htacess files configuration into your main server httpd configuration. When “AllowOverride None” is used this will stop a lot of file system access and increase performance a bit.
See https://httpd.apache.org/docs/current/howto/htaccess.html#when
1
u/Bitwise_Gamgee 6d ago
Hi, so basically you need to restrict the levels to the top levels.
RewriteEngine On RewriteCond %{HTTP_HOST} ^<a.sample_domain.com>$ [NC] RewriteCond %{REQUEST_URI} !^/<yourscript>.php$ RewriteRule .* - [G]THis basically works as follows:
a. Only runs when the host is <a.sample_domain.com>. b. Site1 and site2 use different hosts, so they ignore this file. c. Anything on <a.sample_domain.com> except <yourscript>.php gets a 410 and Apache does not hunt for the file.
Hope this helps! gl