My .htaccess file is in the root directory of my website, and I narrowed down a problem to the single line of code RewriteEngine on. How do I know it's this piece of code? Because I deleted the entire .htaccess file except for RewriteEngine on as a test... and my CGI application still broke.

If anyone has any idea why the RewriteEngine on line decides to break the CGI application all on its own I'd love to hear it!

PS - Just in case you're interested, the piece of code that I want to get working is to help consolidate all domains into a single domain (the line breaks are there simply to make it easier to read):

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html 
RewriteRule (.*) http://www.example.com/ [R=301,L]

Chances are that mod_rewrite is not currently enabled in your Apache configuration (usually in httpd.conf).

If it is enabled, it would look something like this:

# For Unix-like OSes
LoadModule rewrite_module modules/mod_rewrite.so


# For Windows
LoadModule rewrite_module modules/mod_rewrite.dll

as well as

# For both
AddModule mod_rewrite.c

The AddModule line may not be necessary in Apache 2.0/2.2.

Some OSes place Apache module loaders in another directory. On Debian and Ubuntu Linuxes, configuration files for installed modules are in /etc/apache2/modules-available, and can be activated with a2enmod modulename; in this case a2enmod rewrite.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy