htaccess errordocument not working - apache

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

Related

Internal server error with Apache 2.4 in .htaccess on WAMP

The Apache 2.4 documentation mentions .htaccess as a valid context for using the <FilesMatch> directive, with, for example, a Require all denied in it.
Ref: https://httpd.apache.org/docs/2.4/en/mod/core.html#filesmatch
Yet, it leads to a 500 Internal Error if I place it in an .htaccess, and no error if I place it in the main configuration file.
However, it seems like it is less the FilesMatch directive that is a problem than the Require all denied, as no errors occurs if I leave the former empty.
Example of the block that I use:
<FilesMatch "[\._](htaccess|passwd|inf|ini|inc|cls)$">
Require all denied
</FilesMatch>
Any idea of how to make it work in the .htaccess file?

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

Apache rewriting without mod_rewrite?

How can Apache be rewriting URLs without mod_rewrite enabled or configured?
I'm working on a site redesign from my development server. I was using a directory structure for site sections, but I am considering switching to URL rewriting and putting related files in the site's root.
For example, the about page has a subdirectory named about that contains an index.php which is served when the request is http://www.example.com/about. I plan to change this so that about.php from the site's root directory is served even if the request doesn't include the php extension.
On my development server, the problem is that the URLs are already being rewritten even though I don't have an .htaccess file anywhere along the path hierarchy.
The Apache configuration is the stock Ubuntu configuration and I suspect that it's something unique to Ubuntu, but I can't find the cause.
Here are some observations I've made:
/etc/apache2/httpd.conf is empty, but the configuration is in /etc/apache2/apache2.conf which in turn Includes config files from a few other directories.
There were no .htaccess files anywhere in the hierarchy of this site. I've checked every directory starting at /var/www
No .conf or .load files under /etc/apache2 have any reference to rewrite other than the rewrite.load file in /etc/apache2/mods-available.
I've set the LogWarning directive to debug. When I access a page without the .php extension, the error log shows the URL with the extension and the access log shows it without the extension and a HTTP 200 status. The page is served properly.
If I do add a .htaccess file with the appropriate configuration, I get an .htaccess: Invalid command 'RewriteEngine' error. ... mod_rewrite wasn't even loaded by default.
If I enable mod_rewrite by linking to the load file in /etc/apache2/mods-enabled it works as expected, which is to say exactly the same as if I didn't enable it.
access.log shows:
127.0.0.1 - - [16/Jan/2012:05:36:35 +0800] "GET /dev/ghodmode.com/h5bp/ HTTP/1.1" 200 3602 "http://alienware/dev/ghodmode.com/h5bp/experiments" "Mozilla/5.0 (Ubuntu; X11; Linux x86_64; rv:8.0) Gecko/20100101 Firefox/8.0"
while error.log shows:
[Mon Jan 16 05:23:23 2012] [debug] mod_deflate.c(615): [client 127.0.0.1] Zlib: Compressed 5347 to 1876 : URL /dev/ghodmode.com/h5bp/experiments.php, referer: http://alienware/dev/ghodmode.com/h5bp/
If I add an .htaccess file:
[Mon Jan 16 05:34:33 2012] [alert] [client 127.0.0.1] /var/www/dev/ghodmode.com/h5bp/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration, referer: http://alienware/dev/ghodmode.com/h5bp/experiments
Update
Thanks to answers provided, I've been reading and I've learned a few things. The gist of it is that I'm using a stock Ubuntu installation of Apache2 and I haven't changed any configuration settings from the default. So, none of the suggested causes are set.
Of course there is the chance that I've misunderstood some of the documentation. This is the first time I've read about some of these options.
Multiviews
Multiviews provides the best explanation of this scenario, but that requires a type map or MultiViews option set for a path. I only have one type map (/etc/apache2/mods-enabled/mime.conf) for 'var' and the MultiViews option is only set for /usr/share/apache2/icons. So, this couldn't be it.
Redirect & RedirectMatch
Redirect & RedirectMatch would provide a good explanation for this behavior, but it requires a directive for each redirection. I don't have any of these set and any path that I type serves the related php file if it exists. Also, if this was the cause, I think that the access.log would generate a 3xx status instead of 200 if it was a redirect.
Alias & AliasMatch
Alias & AliasMatch, like Redirect & RedirectMatch, requires a directive to be set for each resource. I only have an alias set for /icons/.
FallbackResource
FallbackResource identifies a single resource to serve when the requested resource isn't present. In my case, when the requested resource isn't present it serves the resource found by appending '.php' to the end of the request. I also double-checked and there are no FallbackResource directives set.
Here's an example of the command I use to confirm that there a particular option isn't set anywhere:
find /etc/apache2 -name "*.conf" -exec grep -li "FallbackResource" {} \;
Update #2:
There was a hole in my search for the MultiViews option. I was only looking for files with a .conf or .load extension, but some of the configuration files don't have an extension at all. The MultiViews option is set by the default site configuration file /etc/apache2/sites-enabled/000-default.
Thanks to #zneak for providing the answer first, although he did it in a comment. And thanks to #regilero who indirectly showed me what I was missing by using a different syntax for grep from the syntax I'm used to.
What you call a rewrite can be done by a lot of others instructions:
Redirect & RedirectMatch : for external redirection (with 301,302 or even 403 or 404 codes
Alias & AliasMatch : for internal redirection (internal directory re-mapping for example)
FallBackresource : to redirect every missing file to an index.php boostrap
Option Multiviews : from mod-autoindex which is enabled by default on a lot of installations
Theses configuration things are usually not in .htaccess files by default, as .htaccess files is just a bad thing slowing down apache and allowing user to add some other rules than the one defined in VirtualHosts. Most usefull configuration stuff is in /etc/apache2/sites-enabled, /etc/apaches2/mod-enableds/ and /etc/apache2/conf.d/.
Now the strangest one is Option Multiviews make a grep -R MultiViews /etc/apache2/*. This option will map any call to http://www.example.com/foo/bar to foo/bar.php or foo/bar.html if theses directories exists in the DocumentRoot and if theses files exists (trying on all available extensions).

What does "Directory Index forbidden by rule" mean?

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.

Apache and Internal Server error and internal redirects on WordPress install

I am unable to do WordPress installations automatically on my local Apache for the past 4 weeks. The normal process on another machine goes standard - copy the WP install, run and the install script is executed. What I see here is either blank page, or Internal Server Error.
Even if I do correct manually my wp-config.php file with the settings and install, I receive the same error again. The last WP versions are distributed with no .htaccess so I expect no .htaccess to be required on each install for my local server.
Here there are my httpd.conf settings for the directory:
<Directory "/var/www/html">
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
AllowOverride All
</Directory>
mod_rewrite is loaded here.
I was suspicious about my /etc/hosts as well, but we have the following:
127.0.0.1 localhost localhost.localdomain
I had a look in my php.ini file (PHP is 5.3.3), no specific problems. However, my error log from apache states the following:
[error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
Any ideas?
It sounds like there is either a rewrite rule causing an endless rewrite loop or some other kind of alias loop in your config. Without seeing the rest of your apache config I wouldn't be able to tell for sure.