-
Collection of useful Apache redirects, rewrites, directives and reminders
These are a slew of rewrite and redirection commands for Apache that can be setup in .htaccess or other site configuration files. In some cases there are multiple ways of doing things that might work in one situation but not another. I have a love/hate relationship with mod_rewrite, as I think many do, but in the end it is a powerful tool that can do so much that it is indispensable.
** IMPORTANT – Anywhere you see RewriteXXXXX, make sure you have “RewriteEngine On” to enable it! **
Custom error pages:
ErrorDocument 400 /errors/400.html ErrorDocument 401 /errors/401.html ErrorDocument 403 /errors/403.html ErrorDocument 404 /errors/404.html ErrorDocument 500 /errors/500.html
-
Reverse Proxy from IIS Website to WordPress
Our client has a corporate site at www.domain.com hosted on IIS and the blog hosted on a subdomain on a separate LAMP server at blog.domain.com. Our client feels serving their blog up under www.domain.com/blog will help their SEO and they will rank better (this is debateable but what client wants is what they will get).
The objective of this project is to serve a wordpress site on a linux server under a subdirectory on IIS. In order to accomplish this we need to setup IIS to act as a reverse proxy, thus serving the the wordpress site under the desired blog subdirectory.
The first step is to make sure your version of IIS is compatible (IIS 7+). Once you have determined this, you will need to install the Application Request Routing Module. The easiest way to go about installing these is using the
Read the rest of this entry » -
301 redirect all subdomains to new domain on apache
While trying to consolidate many subdomains under one new domain on apache we had to add the following into the sites configuration file to redirect the multiple subdomains to one. This could be added into the .htaccess as well.
RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^newdomain.com$ [NC] RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301]
-
Blocking IP’s while behind an Amazon ELB with Apache
So Amazon does not allow accept/deny rules on their firewall system which is beyond silly in this day and age, but I digress. If you want to limit access to an apache server behind Amazon’s Elastic Load Balancer, your options are fairly sparse (although there are options).
One such way to accomplish this is to first allow logging of the IP from the ELB using the X-Forwarded-For header. You can see how to do this here.
So once you have setup logging of the IP’s in the apache logs, you now want to adjust the site configuration files. We have individual files in /etc/apache2/sites-available, so we add the following to the specific site. You may do something similar or you may have it all in a httpd.conf, or you can even put this into a .htaccess file.
Read the rest of this entry » -
Logging IP’s on Apache while behind an ELB
We recently had an issue where we had to track the IP’s of the remote hosts connecting to the servers behind our Amazon elastic load balancer. In order to accomplish this we had to adjust the LOGFORMAT of the apache server to log that X-FORWARDED-FOR header that is sent by the ELB. This can vary depending on the server, but you will either need to edit your httpd.conf or apache2.conf file (often in /etc/apache2/).
Add the following to your apache config (comment out the existing settings).
Read the rest of this entry »