Tag Archives: RewriteRule

Rewrite rule to bulk redirect domains using Apache’s RewriteMap

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.

Continue reading

Control server access: Prompt for credentials (basic auth) on approved networks, allow access to itself, and deny everyone else

To get a site feature from development to production, it goes through four servers:

  1. Development
  2. Quality Assurance (QA)
  3. Staging
  4. Production

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.

Continue reading

How to escape pound sign in Apache RewriteRule

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.