A component of the server migration I’m currently working on is to move all of the existing virtual host files. Unfortunately, they’re not all consistently setup, which makes them difficult to overview, and from past experience, difficult to manage.
There is also no easy way to tell which of them represent real sites, and which are purely for redirection. Some even have a document root, implying there may actually be a site there, but often I found only a single
.htaccess file that redirected the domain to another site.
In a previous blog post, I proposed several guidelines to effectively manage virtual host files going forward, and one aspect of that, which I’ll talk about more deeply in this blog post, is how to organize and manage the redirects in bulk.
To get a site feature from development to production, it goes through four servers:
- Quality Assurance (QA)
Except for the development server, which is localhost, there are times people, other than developers, need access to view a particular site on the QA or staging server. In addition, sometimes you need to test your site externally, whether it’d be a mobile device not connected to the network or an external, automated service. This means that the aforementioned servers need to be publicly accessible, but without being accessible to just anyone.
If you’re setting up a redirect and want to redirect to a specific page and “tab” on that page, you need to make sure Apache does not escape the URL, otherwise
# will turn into
%23. You can do that by using the
NE (no escape) flag:
RewriteRule ^/(.*) http://domain.com/services/#development [R=301,NE,L]
That said, it’s probably not a good idea to use
$1 anywhere in your URL, because that would allow a user to supply anything they want and Apache wouldn’t escape that either.