404 Error due to .htaccess file

On my work computer (development), I have Windows, Apache, Mysql, PHP setup to run Zend Framework. For the life of me I could not understand why my .htaccess file was failing to route requests properly, even though I followed all the instructions exactly (including setting AllowOverrides=All, ensuring mod_rewrite was loaded etc).

I was using an Alias block in my .httpd file to use a different virtual directory

Alias /myweb "C:\web\myweb\htdocs"
<Directory "C:\web\myweb\htdocs">      
    Options Indexes FollowSymLinks MultiViews ExecCGI      
    AllowOverride All      
    Order allow,deny      
    Allow from all
</Directory> 

The .htaccess file in my C:\web\myweb\htdocs folder was:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ – [NC,L]
RewriteRule ^.*$ index.php [NC,L]

All redirects were resulting in a 404 (Page Not Found) error. After lots of trial and error, I found out that the error was due to a missing RewriteBase directive!

The following htaccess file fixed the problem

RewriteEngine On
RewriteBase /myweb
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ – [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s