0

I have a legacy web site hosted on Apache. It has a number of web pages sitting in the public web root and its subfolders.

For example's sake, lets say these are the only files and folders in my web root:

publicDocs/
directorywith_no_defaultfile/
    some-legacy-flat-page.htm
.htaccess
index.php
some-legacy-flat-page.htm

I would like to start using Zend MVC for some of the newer pages.

I have got a .htaccess mod rewrite rule working so that any request for a non-existent file is sent to be handled by the MVC bootstrap file (/index.php).

With my current set-up, the following types of requests are successfully routed to '/index.php', the MVC bootstrap:

  • /index.php
  • /blah
  • /directorywith_no_defaultfile/bloo

The following types of request are successfully served by old legacy (flat) pages

  • /some-legacy-flat-page.htm
  • /directorywith_no_defaultfile/some-legacy-flat-page.htm

But, when I request a non-existent file that is a directory like these:

  • /directorywith_no_defaultfile

or

  • /directorywith_no_defaultfile/

instead of routing these to the MVC bootsrap, I get an error:

Forbidden    
You don't have permission to access /directorywith_no_defaultfile/ on this server.    
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

I suspect this may have something to do with the way Apache handles default files.

Currently, the only way to solve it is to:

  • delete that directory (which is not possible while it holds flat legacy pages), or
  • put an index.htm file in there which contains a script that include()'s the bootstrap file

Do you know which Apache directives could be causing this 'Forbidden' error?

Are the any directives i can use in .htaccess to tell Apache to 'chill out' about missing default files in directories and just leave it to the mod-rewrite to worry about?

2
  • Can you add the relevant bits of your .htaccess file to the question?
    – meulop
    May 13, 2010 at 21:30
  • I was hoping I would not get asked that :o) - The real .htaccess file is constantly changing as I hack away and experiment But, yes. I will make a start on trying to piece together an example that works as a kind of 'proof of concept'. Was mainly wondering if anyone had experienced this before could say "aaah! I had this issue the basic principal is to ensure xyz to avoid it"
    – j w
    May 13, 2010 at 22:04

2 Answers 2

1

The documentation for the DirectoryIndex directive includes the following:

Note that the documents do not need to be relative to the directory;

DirectoryIndex index.html index.txt /cgi-bin/index.pl

would cause the CGI script /cgi-bin/index.pl to be executed if neither
index.html or index.txt existed in a directory.

So, adding the following line in the appropriate places should do it:

DirectoryIndex index.html index.php /index.php

Tweak this to include support for whatever types of index files you want to be handled normally. As long as "/index.php" is the last one, it should do what you want.

1
  • yep. that solves it thanks. (It limits it to one 'mod-rewritten default bootstrap for directories with no default file' per .htaccess - but i can live with that.)
    – j w
    May 14, 2010 at 19:12
1

This is how I generally setup my mod_rewrite script in the .htaccess file

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    rewriterule ^(.*)$ http://www.domain-name.com/$1 [r=301,nc]
</IfModule>

Hope that helps!

1
  • yes, always handy to see how others do it.
    – j w
    May 14, 2010 at 19:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .