Tag Archives: Apache

Apache htaccess and directive multiviews

Nowadays it is common to use a .htaccess file to configure access to directories and also mask URL’s that point to internal URL’s. Well today, we had to point a URL of http://www.mydomain.com/solution to an internal URL like http://www.mydomain.com/solution.cfm.

Actually no big deal, since the .htaccess comes to the rescue. We quickly put a .htaccess together with the simple lines of:

RewriteEngine On
RewriteRule ^([a-z]+)$ /$1.cfm

But alas, it did not work. We always got an error message saying that the URLĀ  http://www.mydomain.com/solution could not be found. We thought that the .htaccess file was not working or we had a typo. We even restarted the whole server to see if that had any effect. But still we could not get the rewrite rule to work. Strangely the rule *did* work when we used something like:

RewriteRule ^([a-z]+)$ /test.cfm

Apparenlty, Apache was looking for the same directory and was not matching our rule, but only if the URL and the filename had the same name! So, after a long time looking for a solution we figured out that we had “Multiviews” enabled for all of our hosts. Multiviews is part of the “Content Negotiation package” of Apache. In its own words “Content Negotiation” is about;

“It can choose the best representation of a resource based on the browser-supplied preferences for media type, languages, character set and encoding. It also implements a couple of features to give more intelligent handling of requests from browsers that send incomplete negotiation information.”.

Point is that the Multiviews directive interefered with our rewrite rule. Thus the solution to get our rewrite rule to work properly was to add a custom directive to the host in question without the Mutliviews option.

A comprehensive documentation on Multiviews can be found over at the Apache docs.

Comments { 11 }

Apple Security Update 2008 – 002

Looks like a Update Day from Apple. Apple just released the “Security Update 2008 – 002″ for 10.5.2 and I believe 10.4.11. The update addresses some issues with;

  • Apache: Updated to 2.2.8/1.3.41 to address several vulnerabilities
  • FireWall
  • OpenSSH: A remote attacker may be able to execute arbitrary code with elevated privileges
  • PHP: PHP is updated to version 5.2.5/4.4.8 to address multiple vulnerabilities
  • Preview: Saving to encrypted PDF in Preview produces files that may be read without the password
  • and much more…

Looks to be quite an important update for your own safety. You can read up on the full release notes here. The update can be obtained with the build in Software Update function.

Comments { 3 }

Moving WordPress installation from Windows Server 2003 to Linux

We just finished moving our blog (the one you are reading now) from Windows Server 2003 to CentOS 5. The switch included a couple of steps, but was rather easy:

  1. Install CentOS with Apache, PHP and MySQL. CentOS does install Apache 2.2.3, PHP 5.1.6 and MySQL 5.0.22 by default. Make sure to “yum update” to get the latest stable packages.
  2. Make a backup of all your WordPress database on the original server. To do this we used the excellent “wp-db-backup“. Just backup all of your tables and download it to your machine. You will then have a backup.sql file.
  3. Create a database in your NEW Worpress server, rename the backup.sql file to be the same as the database and import the backup.sql file with the following command:
    mysql -p -h localhost dbname < dbname.sql
    Now all your posts, comments and all, are imported in the new database and ready to use.
  4. Install and/or copy your WordPress installation. We are always using the Subversion WordPress and thus had to checkout the WordPress installation and copied our plug-ins and themes from the Windows installation to the Linux one.
  5. On Windows we used to have permalinks like “/2008/02/04/mypost”. To make it work on IIS we used a rewrite tool that used the same syntax as the rewrite modul on Apache. To make it work on Linux with Apache we had to do the following:
    1. Enable “LoadModule rewrite_module modules/mod_rewrite.so”
    2. Set the “AllowOverwrite” controls to “All” with: “AllowOverride All” (this is very important or else your permalinks will not work)
  6. Restart Apache with “/sbin/service httpd restart”
  7. Make the needed configuration in your DNS and Apache vhost containers.

A word on WordPress. We are really just a ColdFusion shop, but the WordPress package as a whole is really just a convincing offer, independently of the language in the back. I have never seen a blog application that is so full featured and easy to use and setup. The sheer amount of plug-ins and themes are a major plus. Anyhow, back to coding some real stuff in ColdFusion .-)

Comments { 91 }

Custom 404 pages with ColdFusion 8, MacOS X and the difference with IIS

For one of the projects we are working on (news will be revealed very soon) we will need to redirect a clean URL like “http://www.mydomain.com/mybox” to a certain record.

Of course, our first thought was that it is easy to create a custom 404 page, add this to the web server configuration, get the query_string and do some stuff with it. Easy right?

Well, in our findings we see that Apache 2.2.6 gives us a empty query_string, where as IIS on Windows Server 2003 returns a nicely formated query_string in the form of “404;http://www.mydomain.com:80/mybox”. Needles to say, that this posts a challenge since we would need to have the “mybox” part of the URL to make something meaningful with it.

Here are the following steps to make this work on Apache.

1. Create a custom 404 page

Simply create a new ColdFusion page. We called ours “404.cfm” and put it in the web root (or in the root of your host directory). Within the template add a <cfdump var=”#cgi#”> or a #cgi.query_string#.

2. Add this to the httpd-vhosts.conf file

Since we are working with different local hosts we are changing the virtual host directives, this gives you a additional value to have custom 404 error pages for each host. If you don’t need that or simply want to have a general 404 page then edit the httpd.conf file and change or add the line “ErrorDocument 404 /404.cfm” (around line 414 in the httpd.conf file).

For virtual hosts do the same, but simply put this line “ErrorDocument 404 /404.cfm” within the virtualhost directive!

3. Restart Apache and test

Within the terminal restart Apache with “/usr/sbin/apachectl restart”. Now surf to the URL “http://www.mydomain.com/mybox”. Do you land on your custom 404.cfm page? If so, you should see a empty “query_string”. If you get an error instead of your page, make sure that you have done step 1 and 2 correctly.

Ok, once it is working we can now get on with the show. That is, we will need to get the rewrite module working. Without it enable, you will never get the query_string value filed. Good thing is, that Apple included Apache 2.2.6 and already compiled it with the rewrite module. If your installation varies or you try this on another Apache version then make sure you compiled Apache with the rewrite module.

4. Check for the rewrite module

Again go into your httpd.conf file and look for the line “LoadModule rewrite_module libexec/apache2/mod_rewrite.so”. Make sure it is NOT commented (that means, is does not have a “#” in front of it).

You will also need to look for the line “AllowOverride None” (about line 210) and change it to “AllowOverride All”.

Save and close httpd.conf.

5. Create a .htaccess file

This part is the key to all of the above. Create a new file, called “.htaccess” and put it in the directory of your 404.cfm page. within the .htaccess file add the following lines:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /404.cfm?%{REQUEST_URI}

This will make sure that the complete URL string gets passed to your 404 page and thus in the cgi.query_string scope.

6. Restart Apache and test

Within the terminal restart Apache with “/usr/sbin/apachectl restart”. Now surf to the URL “http://www.mydomain.com/mybox”. You should see the “mybox” part now in the query_string.

That’s it. Hope this helps some others as we have spent quite some time figuring this out.

Comments { 62 }