Category: Apache

Redirect Old URLS In .htaccess

Frequently when our clients upgrade their website, they will need URLs from the old site mapped to the new site. So for example maybe they had this URL on the old server: http://acme.com/widgets/egonomic-widget-design Maybe there are many sites on the Internet that link to this URL so they don’t want it to return a 404 error. Instead they want it to redirect to the new address of the article at: http://acme.com/smallwidgets/designing-egonomic-widgets This can be accomplished with a simple rewrite rule in the .htaccess file like this: RewriteEngine On Rewriterule ^widgets\/egonomic-widget-design$ http://acme.com/smallwidgets/designing-egonomic-widgets [R=permanent,L] Note that the RewriteRule should be on one line in the file … not wrapped over two lines. The pattern for the rewrite rule is:

Also notice that in the source pattern we escaped the slash (/) with a backslash (\). This is necessary since the slash has special meaning in a regular expression. In the above

Read More »

Install SSL Certificate – Apache / CentOS / RHEL

For this example we’ll install an SSL certificate for acme.com. The certificate authority is Network Solutions. The procedure may be different for other certificate authorities especially in how intermediate certificates are setup. Install mod_ssl if needed

Copy SSL certificate to the server – The certificate should be named after the domain name and placed in the /etc/pki/tls/certs folder. For our example the cert will be:

Copy the intermediate CA bundle to the server – The bundle should be placed in /etc/pki/tls/certs/ and named after the certificate authority. For example, GoDaddy would be “gd_bundle.crt” and Network Solutions would be “ns_bundle.crt”. Sometimes the certificate authority will provide the bundle file. Other times they will just provide a set of separate root and intermediate CA certificates. In this situation, you’ll need to create the bundle file yourself. The bundle is a text file with a series of certificates. The first certificate

Read More »

Rewrite Rule To Block User Agent

Recently we’ve seen servers being overloaded by the 80legs.com web crawler. Here’s a quick rewrite rule that can be placed in .htaccess to block 80legs:

Here’s a rule to block by user agent with Nginx:

Read More »

Set Apache To Start On Boot

By default many Apache RPM packages do not set the httpd server to start automatically on boot so this needs to be done manually. On RedHat/CentOS the chkconfig command should be used as follows:

Read More »

Apache Configuration Best Practices

There are numerous ways to organize your Apache configuration files. In some cases this organization will be dictated by your Linux distribution or control panel choice. When I’m working on RedHat/CentOS with no control panel here’s what I have found to be a good organization: Minimize changes to /etc/httpd/conf/httpd.conf. It’s easier to upgrade or migrate if this file has few or not changes. Place virtual host definitions in /etc/httpd/conf/vhosts.conf. Put the document root for each website at /var/www/vhosts/[domain name]/httpdocs. Do not include “www” on the domain name. For example with “acme.com” the document root would be /var/www/vhosts/acme.com/httpdocs. Here’s a template for the virtual host definition:

Of course the SSL portion of the template is optional.

Read More »

Categories

Get a free consultation from Reliable Penguin

Submit the form—or for immediate service call 866-649-7984.