What does "Directory Index forbidden by rule" mean? - apache

What could the following line mean?
[Mon Feb 21 20:52:13 2011] [error] [client 66.249.71.150]
Directory index forbidden by rule: /var/www/vhosts/website.com/httpdocs/
I have no index.php in the root, since my index is home.php, website root file is defined by .htaccess rules:
My .htaccess file looks like this:
DirectoryIndex index.php /index.php
RewriteCond %{HTTP_HOST} ^website.com$
RewriteRule ^$ en/home [R=301,L]
...
Thanks very much!
update1:
I dont have access to the virtual host config files, im on shared hosting , so only .htacces in my /httpdocs/ thats all I have. What should I do? Should I jus disable DirectoryIndex (I dont use that anyways and the site works fine!) How can I check wether I have directory index or not?
update2:
when testing in browser, all seem to work fine, fast and nicely!
in log however, i see this:
[Sun Feb 27 02:18:56 2011] [error]
[client 66.249.71.81] File does not
exist:
/var/www/vhosts/website.org/httpdocs/index
Unlike the first error at the top of this page, this seems a regular 404 (my 404 error document is my home page, so error pages show the home)
When I type in 'website.org' the htaccess rule does goed job in redirecting to the default page website.org/en/home and when I type 'websie.org/index' it redirects to website.org/en/home so it all seems to work fine but i dons know what the two error means "Directory index forbidden by rule..."
Clues? Thanks!

EDIT 2: Ok... I think I just completely misread this question at first. You say you don't have an index.php file in the directory? If so, DirectoryIndex index.php /index.php doesn't look correct. Maybe you should try changing that to:
DirectoryIndex home.php
Am I understanding the issue correctly? You're trying to display the default page for the directory, correct?
By default, some http.conf setups have the following rule:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
Whenever I set up a vhost, I often change this rule to look more like this:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>
The important parts in your case are the last two pieces Order and Allow.
EDIT 1: Actually, after looking into this error a bit more, it's possible that this is even a permissions issue. Can you double-check that Apache has read access to the directory you're trying to access?

Check your entries and make sure that your site's virtual host DocumentRoot is listed there, otherwise apache won't be able to get at it.

Related

htaccess shows "Not Found" if directory does not exist

I want rewrite everything that matches <domain>/something/mypage.htm to something.php?pid=mypage, so I wrote the following .htaccess file:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).htm$ $1.php?pid=$2
DirectoryIndex home.php
On my old webhosting provider, the rules worked as expected, but on the new provider, it says "Not Found" when I try to open <domain>/something/index.htm or similar. But when I create a directory called something, the rewrite rule works as expected.
Is anyone having any idea what's wrong here?
It looks like MultiViews is perhaps enabled on the new server and this will conflict with your mod_rewrite directive.
With MultiViews enabled and you request /something/mypage.htm (when /something.php exists as a physical file), mod_negotiation will issue a subrequest for /something.php/mypage.htm (that's /something.php with path-info of /mypage.htm) before your mod_rewrite directive is able to process the request, so no pid parameter is passed. (Your directive does not match a dot in the first path segment, so the subrequest by MultiViews does not match.)
The 404 will result from either Apache, if AcceptPathInfo Off is set (perhaps in the server config), or from your script because the pid parameter is not being passed.
When you create a subdirectory called something, MultiViews does not rewrite the request since it already matches something, ie. the directory by that name.
You need to ensure that MultiViews is disabled at the top of your .htaccess file:
Options -MultiViews
NB: MultiViews is not enabled by default on Apache, but some shared webhosts do enable it for some reason. It makes extensionless URLs "magically" work out of the box, but actually causes many more problems if you are not expecting it.

Apache visit abc.com/api/xxx auto rewrite to api.com/api.php

When I visit localhost/api/xxx auto rewrite to localhost/api.php, how to cancel this role? I can't find this rewrite conf.
I also check the .htaccess file and clear it , but that doesn't work.
Server version: Apache/2.4.16 (Unix)
Probably you have MultiViews option enabled. You can turn it off by placing the following line in your .htaccess file.
Options -MultiViews

htaccess errordocument not working

My understanding is that to show a custom error page, one must put
ErrorDocument 404 /error/404.php
in .htaccess
Also,
AllowOverride All
must be set in httpd.conf file. However, right now it's set to
AllowOverride None
If I change None to All, then restart the server, I get a Internal Server Error 500 when I deliberately enter gibberish in the address bar. What am I doing wrong?
Other things in the file
IndexIgnore *
followed by
RewriteEngine on
followed by rewrite rules.
RewriteEngine on is the cause of the problem--see below.
Short answer: This error means you forgot to enable the rewrite module and is not related to ErrorDocument.
How to fix it?
Make sure you have enabled the rewrite module. This can be done by doing one of the following:
Uncommenting LoadModule rewrite_module modules/mod_rewrite.so in your Apache configuration file.
Run a2enmod rewrite as root (only available on Debian-based systems).
Why are you only getting this error after you added ErrorDocument?
AllowOverride was set to None, which means your .htaccess will be completely ignored. Later, you set it to All to enable .htaccess files.
However, you forgot to enable the rewrite module but you tried to use it in your .htaccess. This is not related to ErrorDocument and is simply a coincidence. The following error you posted is clearly showing it:
[Sat Aug 17 17:33:46 2013] [alert] [client 127.0.0.1] C:/Data/MyWeb/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

htaccess <Directory> deny from all

I've been cleaning up my project lately. I have a main .htaccess in the root directory and 6 others. 5 of them ran Options -Indexes which i didn't see anypoint of allowing any Directory viewing so moved that to the main one. so now i only have 2 .htaccess files. the main and one in /system which holds
# Block External Access
deny from all
So i wanted to run that on /system only from within the main. So i deleted the one in /system and added
# Block External Access
<Directory "/system/">
deny from all
</Directory>
to my main .htaccess file leaving 1!
but now i get a
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator, webmaster#localhost and
inform them of the time the error occurred, and anything you might
have done that may have caused the error.
More information about this error may be available in the server error
log.
Apache/2.2.17 (Ubuntu) Server at 10.0.1.5 Port 80
The goal is to block reading any files in /system and it's sub directory's but allow viewing of everything else all from one .htaccess file for the whole project. Any ideas on how i can fix this? I did some Google searches but couldn't really come out with anything.
You cannot use the Directory directive in .htaccess. However if you create a .htaccess file in the /system directory and place the following in it, you will get the same result
#place this in /system/.htaccess as you had before
deny from all
You can also use RedirectMatch directive to deny access to a folder.
To deny access to a folder, you can use the following RedirectMatch in htaccess :
RedirectMatch 403 ^/folder/?$
This will forbid an external access to /folder/ eg : http://example.com/folder/ will return a 403 forbidden error.
To deny access to everything inside the folder, You can use this :
RedirectMatch 403 ^/folder/.*$
This will block access to the entire folder eg : http://example.com/folder/anyURI will return a 403 error response to client.
You can use from root directory:
RewriteEngine On
RewriteRule ^(?:system)\b.* /403.html
Or:
RewriteRule ^(?:system)\b.* /403.php # with header('HTTP/1.0 403 Forbidden');

RewriteRule in .htaccess not working

I am currently running Apache2 on my local machine, installed with the latest version of Ubuntu.
I am trying to get basic URL rewriting working by using the .htaccess file.
The file "http://localhost/page.php?=home" does exist, and the location "/doesnotexist/home" does not.
I would like to have the first page be loaded when the second is requested.
My .htaccess file looks like this:
RewriteEngine On
RewriteRule ^/doesnotexist/(.*)$ /page.php?p=$1
My httpd.conf file looks like this:
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
<Directory /var/www>
AllowOverride All
</Directory>
Note that my httpd.conf file looks exactly like that, as it was empty before I edited it.
The result that I get is this:
Not Found
The requested URL /doesnotexist/home was not found on this server.
I have googled the ever living **** out of this problem, and I have never gotten anything other than the error above.
If anyone has any ideas, I would be very appreciative.
For the benefit of others, I figured out the answer:
In the file "/etc/apache2/sites-enabled/000-default" there was the line:
AllowOverride None
Change this to:
AllowOverride All
You need to remove the contextual path prefix from your pattern when using mod_rewrite in a .htaccess file. In the case of the root directory, the path prefix is just /. So try this:
RewriteRule ^doesnotexist/(.*)$ /page.php?p=$1
If I place a .htaccess into /Library/WebServer/Documents and open "localhost/"; to test it, this works as expected. It just doesn't work in "~/Sites". I have tried this on Mac OS X Mavericks.