Monday, November 3, 2014

Apache 2.2 errors: attempt to serve directory, no rewrites



Setup: Apache 2.2 (Windows, win32).




httpd.conf snippets:



Alias /custom /var/www/custom

DirectoryIndex index.html


SetHandler custom_handler
DirectoryIndex index.html




Allow From all
Options +Indexes
AllowOverride all
DirectoryIndex index.html



Also:





  • mod_dir, mod_rewrite activated

  • index.html present in /var/www/custom

  • server process UID may read all files/directories in /var/www

  • Apache service listens at all interfaces

  • custom handler processes certain URLs within Location path, other are served from file system; index.html is processed as if no handler is present



Problems:





  • rewriting URLs starting with the Location path are not working (no errors reported)

  • when trying to serve http://server/custom (without closing slash), the following happens:


    • Apache redirects to http://ServerName/custom/ (to ServerName directive value)

    • "Attempt to serve directory" is written to error log for /var/www/custom/

    • 404 error is returned





How the above can be handled? The following is requried:




  • serve /var/www/custom/index.html when http://server/custom is entered, or

  • rewrite certain URLs, like




    RewriteRule ^custom/$ /custom/index.html [L,R]






The above rewrite rule doesn't work, wherever it's placed (in or outside Location)


Answer



You're mixing several different ways of mapping an URI to a part of the file system, and they don't all work together.



Firstly, if your DocumentRoot is /var/www, then the AliasMap is completely unnecessary. This isn't clear from your snippet, though.



Second, since /var/www/custom is a directory, you should use the Directory directive when you refer to it. Location is used for things that aren't directories but that you would like to act as if they were.




To clear these points, try changing your config like this:



Alias /custom /var/www/custom  # ONLY if you don't have /var/www as DocumentRoot!

DirectoryIndex index.html


Allow From all
Options +Indexes

AllowOverride all



SetHandler custom_handler


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...