I work as a web developer, creating custom websites for customers. My .htaccess files are generally very simple. I generally only do 2 things:
/upload directory to /admin/upload to simplify some shared code between the public website and the admin systemI have everything working okay, other than one slight annoyance I'm wondering if anything can be done about. I'm using php, and I try to design the websites in a modular fashion, so that it doesn't matter whether the code is hosted at "example.com/" (the real domain), "localhost/exampleproject2" (on my development machine), or "mycompanywebsite.com/example.com" (Where we host a "beta" version for the customer to view when we get to that point in development).
From the PHP side of things, I have no issues here. But so far as Apache is concerned, I have to create 3 slightly different .htaccess files for each of those domains:
ErrorDocument 404 /404.php
Redirect 301 /upload /admin/upload
ErrorDocument 404 /exampleproject2/404.php
Redirect 301 /exampleproject2/upload /exampleproject2/admin/upload
ErrorDocument 404 /example.com/404.php
Redirect 301 /example.com/upload /example.com/admin/upload
Obviously this is not a huge deal, but it is a bit annoying. Mostly when I or someone else transfers files over FTP and accidentally overwrites the .htaccess from one environment with it's counterpart from another environment, and the site breaks. Also it means I can't include .htaccess in my git repository without possibly breaking things.
From my testing, relative urls don't seem to work at all. I think maybe Apache just doesn't support relative urls in .thaccess files for Redirects and ErrorDocuments. At least that's the way it seems. I get a server error when I try.
I'd like a way to have a single .htaccess file I can share between all 3 environments and include in the git repository. If anyone knows a good way to accomplish this that would be awesome. Solutions don't have to use .htaccess, I'm open to any solution that makes my code less dependent on absolute paths or urls.