Home > database >  error accessing web htaccess AH01797: client denied by server configuration
error accessing web htaccess AH01797: client denied by server configuration

Time:05-03

I'm getting error when i open my website externaly. I'm getting this error: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.

If i delete my .htaccess, it is not giving me error, but is showing me the path of /htdocs and i have configured a SubFolder.

If i open localhost:80 it redirects correctly to the subfolder htdocs/folder-name The problem is when i open it via www.domain.com externaly.

This is my .htaccess. Path: C:\Apache24\htdocs.htaccess Content:

#DON'T SHOW DIRECTORY LISTINGS
 Options -Indexes

#FOLLOW SYMBOLIC LINKS
 Options  FollowSymLinks

#SET DEFAULT HANDLER
 DirectoryIndex index.html index.php

 RewriteEngine on
RewriteCond %{HTTP_HOST} ^DOMAIN.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.DOMAIN.com$
RewriteCond %{REQUEST_URI} !FOLDER/
RewriteRule (.*) /FOLDER/$1 [L]


#ERROR 404 PAGE
 ErrorDocument 404 /404.html
                  

APACHE LOG:

client denied by server configuration: C:/Apache24/htdocs/WEBSITE-XX/
[AH01797: client denied by server configuration: C:/Apache24/error/HTTP_FORBIDDEN.html.var
 AH01797: client denied by server configuration: C:/Apache24/htdocs/WEBSITE-XX/favicon.ico, referer: https://www.example.com/
 AH01797: client denied by server configuration: C:/Apache24/error/HTTP_FORBIDDEN.html.var, referer: https://www.example.com/

** rewrite module is active and the path is correct **

httpd.conf code of VirtualHost

EDIT

<VirtualHost *:80>

    ServerAdmin [email protected]
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot C:\Apache24\htdocs\example
    ErrorLog C:\Apache24\logs\error.log
    CustomLog C:\Apache24\logs\access.log combined

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =example.com [OR]
    RewriteCond %{SERVER_NAME} =www.example.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>

<VirtualHost *:443>

    ServerAdmin [email protected]
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot C:\Apache24\htdocs\example
    ErrorLog C:\Apache24\logs\error.log
    CustomLog C:\Apache24\logs\access.log combined

    SSLEngine on
    SSLCertificateFile C:\Apache24\conf\certificate.crt
    SSLCertificateKeyFile C:\Apache24\conf\private.key

</VirtualHost>

**** EDIT WITH NEW HTTPD.CONF ****

<VirtualHost *:80>

    ServerAdmin [email protected]
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot C:\Apache24\htdocs\example
    ErrorLog C:\Apache24\logs\error.log
    CustomLog C:\Apache24\logs\access.log combined
<Directory C:\Apache24\htdocs\example>
    # Requried for mod_rewrite (and disable Indexes / MultiViews)
    Options FollowSymLinks

    # Allow access
    Require all granted

    # Enabled .htaccess overrides
    AllowOverride All
</Directory>
    Redirect 301 / https://example.com/
    # RewriteEngine on
    # RewriteCond %{SERVER_NAME} =example.com [OR]
    # RewriteCond %{SERVER_NAME} =www.example.com
    # RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>

<VirtualHost *:443>

    ServerAdmin [email protected]
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot C:\Apache24\htdocs\example
    ErrorLog C:\Apache24\logs\error.log
    CustomLog C:\Apache24\logs\access.log combined
    
<Directory C:\Apache24\htdocs\example>
    # Requried for mod_rewrite (and disable Indexes / MultiViews)
    Options FollowSymLinks

    # Allow access
    Require all granted

    # Enabled .htaccess overrides
    AllowOverride All
</Directory>

    SSLEngine on
    SSLCertificateFile C:\Apache24\conf\certificate.crt
    SSLCertificateKeyFile C:\Apache24\conf\private.key

</VirtualHost>
````

CodePudding user response:

<VirtualHost *:80>
    :
    DocumentRoot C:\Apache24\htdocs\example
    :

<VirtualHost *:443>
    :
    DocumentRoot C:\Apache24\htdocs\Mymxtools

Confusingly, you have defined a different DocumentRoot for the two VirtualHosts. (Maybe this is an error in your exemplification?) Although you are redirecting everything to HTTPS, so this doesn't really matter as it happens.

However, you have not "allowed" access to this part of the filesystem or enabled .htaccess overrides.

You would need something like the following in the <VirtualHost *:443> container to grant access and enable .htaccess overrides.

<Directory C:\Apache24\htdocs\Mymxtools>
    # Requried for mod_rewrite (and disable Indexes / MultiViews)
    Options FollowSymLinks

    # Allow access
    Require all granted

    # Enabled .htaccess overrides
    AllowOverride All
</Directory>

Aside:

RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

To redirect everything from HTTP to HTTPS in the <VirtualHost *:80> container, you don't need this "complex" mod_rewrite rule. A much simpler mod_alias Redirect is sufficient (and preferred).

For example, use the following instead:

Redirect 301 / https://example.com/

You should canonicalise the hostname at this stage. Your previous mod_rewrite rule would preserve the hostname, ie. www or non-www.

  • Related