First of all
I thought it was a little strange when you said it:
Created c: wamp www denyfolderwindows
...
I created a . htaccess file within c: wamp www myfolder ...
If it really is like this, the .htaccess
who is in myfolder
there is no way to affect the folder denyfolderwindows
. Each of the .htaccess
of a host goes to the folder where it is, and subfolders inside it. "Neighbor" folders are not affected.
The correct in a scenario like the one above would be by the .htaccess
at least in c:\wamp\www\
.
But assuming it’s just the wrong example, let’s go to other possibilities.
Returning to the Apache
According to the apache documentation, you can configure the directive ErrorDocument
in four different contexts.:
- config server
- virtual host
- directory
- .htaccess
Since your . htaccess may not be accessible, you have the other 3 options, the server config
the main context, which affects Apache as a whole. Generally apache.conf, or httpd.conf.
The Virtual Host is the context used when you serve multiple domains on the same IP. Using the Error Document
inside virtual hosts you can customize different pages for each site.
If you need more granularity, with error 403 showing different pages in different subdirectories, and cannot use .htaccess
, is the case of using the context directory:
<Directory /minhasubpasta/pastasecreta>
ErrorDocument 403 /rickrolled.html
</Directory>
<Directory /minhasubpasta/filmes>
ErrorDocument 403 "403 Access Denied. Olá amiguinho, a senha é SWORDFISH"
</Directory>
Regardless of permissions, so that the Error Document
works on . htaccess, it is necessary to check the directive Allowoverride in httpd.conf.
She must have at least the flag FileInfo
qualified, other than the .htaccess
is ignored as a whole. Option All
, as the name already says, it allows everything, but usually it is not what is desired in a lodging. In turn, None
is very restrictive. The documentation has a better description of the options of this Directive.
File permissions
Remember that Apache will only serve the pages and directories that it can access. This also applies to configuration files, including .htaccess
.
It doesn’t matter at all the file permissions of the user who is browsing the site, only those of Apache.
In many Linux distros the Apache user is usually the 48, and he has to have read access to everything he uses.
In Windows it is similar. Once you know this, in Windows security permissions you must allow Apache access to all work files. When in doubt, it is good to look, for example in the Task Manager (show all users' processes, if applicable) and notice who is the parent of the child.
In Windows, the simplest is to run it as SYSTEM, or better yet, installed as Service, so he’ll have the basic privileges to do what he needs. If it is an installation for an application in production environment, you can create a separate user for Apache (it is even the most recommended), but you have to understand the necessary file permissions, not to complicate.
In the latter case, by creating a .htaccess
new, remember that it may have been created with your credentials, not the ones that Apache can use. It’s hard to get into a situation like this in normal everyday life, but it’s good to know it’s not impossible.
Peculiarities of Windows Explorer
For those who are in Windows, has another interesting detail: it is very good that the option "evil" to hide the extension types for known files is turned off, because most of the time it hinders. For example, malware "arquivotexto.exe" with an innocent icon passes through a mere document.
In the case of .htaccess
can happen the same. Suddenly one thinks he has created a .htaccess
, but there’s a .htaccess.txt
. By the way, if you create a .htaccess
directly by the Explorer and it does not complain, something is wrong.
Windows 7 simply won’t let you create one .htaccess
directly by Explorer, or rename an existing file to .qualquercoisa
, because he considers it an unnamed file. And it’s no use to want to rename.
The solution? There are several, how to create from scratch in your code editor and save, download one via FTP and change the content, or create via CMD:
echo # > .htaccess
Beware of Internet Explorer
And a few more browsers. It often happens that your custom error is working, but it doesn’t show up because IE detects very short error messages, and exchanges them for the internal versions of it. The solution to this is to increase the number of bytes on the page to more than 512 bytes.
The answer to this is simple. The user that Apache is running has no read permission in the directory. It’s different than denying access. To show an error message it is necessary to create a rule, which can be url rewriting.
– Marcos Regis
@Marcosregis I do not know if I did not make myself understood, this for me is clear, what I want is to be displayed the page I set up in
ErrorDocument
instead of the standard apache error page.– Guilherme Nascimento
Apache in Windows is usually run with your user. If this user does not have the proper permissions he will not have it either. Remember that not only the target directory has read permission, its parents also need such permission. This is checked before Apache can check what kind of answer it can give. In time, this problem is not of programming which will probably cause someone to signal.
– Marcos Regis
@Marcosregis The problem whether it is possible or not to be theoretical induces a tool used in development, Apache, if Apache can present an error page from
apache2\error\HTTP_FORBIDDEN.html.var
then why not present a custom page? If apache crashes or emits aWarning
then you really would be correct. But that’s not the case. So if it’s not possible, then the answer would be "not possible," but it’s not really off-topic.– Guilherme Nascimento
I get your point now. The problem is that Voce seems to have changed the answer in . htaccess but since Apache cannot read the directory, you will never get the text from it. To do this, Voce needs to change Errordocument directly at httpd.conf
– Marcos Regis
Biggest reward I’ve ever seen :-)
– Ricardo
@Ricardo I also did not find any question that had such a reward :) - but I could be wrong
– Guilherme Nascimento
@Guilhermenascimento you could remove content from the default page by custom content ?
– Ricardo
@Ricardo I believe not, because it is something internal of the apache, I even searched in the documents, but I’m not sure
– Guilherme Nascimento
@Guilhermenascimento unless I’ve got it wrong, just set it up in apache.conf and put the error page in a folder accessible by everyone, or even put the custom message right in the file, if it’s textual.
– Bacco
Example, straight to apache.conf:
ErrorDocument 403 "Ei, aqui nao pode."
You need to see if Allowoverride is allowing you to change this in htaccess as well. The Document error can be set to server config, virtual host, directory and . htaccess.– Bacco
@Bacco can’t find such an apache.conf file, it would be httpd.conf?
– Guilherme Nascimento
It can be, depending on the package. If you don’t want to literal, you can put the path in htaccess. Just put it in a place where apache has access. https://httpd.apache.org/docs/2.2/mod/core.html#errordocument
– Bacco
@Bacco seems to be right, the test worked here, I will test tomorrow all right to confirm :) Thank you!
– Guilherme Nascimento
@Guilhermenascimento you can configure pro 403 show different pages in different folders even without htaccess, just use a <directory> for each path. There is an example in the link I put.
– Bacco
@Marcosregis Strangely recreating all the folders from www to www internal folders started working, I didn’t have to touch Apache and no configuration, I tried to check all users of the original www folder, but it looked identical to the new folder, I can only assume that Windows is somewhat of a sequel :p - Thank you!
– Guilherme Nascimento