Forbidden You don't have permission to access / on this server [closed]
Asked Answered
L

6

68

All I wanted to do today was to write a redirect rule to a subfolder, e.g.: You enter the URL: example.com and you get redirected to example.com/subfolder

Such a simple wish. I tried to find a solution on the internet. The internet told me to add an .htaccess file in the htdocs root with:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ subfolder [L]

I did this. But no success obviously, they didn't told me I had to uncomment the module in httpd.conf:

LoadModule rewrite_module modules/mod_rewrite.so

So I did this too. No success again. They didn't told me I had to change my httpd.conf so that the .htaccess file would be enabled:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

DocumentRoot "c:/Apache24/htdocs"
<Directory "c:/Apache24/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Again no success, because I get this error when entering the URL:

Forbidden You don't have permission to access / on this server.

Now I'm stuck and I couldn't find any more solutions on the internet. I'm just running Apache 2.4 on my Windows 7 machine, for private reasons.

Lizarraga answered 4/2, 2014 at 11:56 Comment(2)
possible duplicate of Apache permission deniedMichaelemichaelina
Where can i find the httpd.conf on apache2.4?Hypotaxis
L
171

Found my solution thanks to Error with .htaccess and mod_rewrite
For Apache 2.4 and in all *.conf files (e.g. httpd-vhosts.conf, http.conf, httpd-autoindex.conf ..etc) use

Require all granted

instead of

Order allow,deny
Allow from all

The Order and Allow directives are deprecated in Apache 2.4.

Lizarraga answered 4/2, 2014 at 14:46 Comment(7)
holy hell, just migrated from centos and i'm super glad i saw this. Thank you!Spumescent
Damn Deprecation! - Apache error message would have been nicePrehensile
yes, totally aggree with @AndrewAtkinson. years of apache2, and now, same version, different config.Pasahow
Thank you! The default magento 1.9.1 .htaccess used the deprecated way.Coupler
Sorry to ask but where exactly should we put that line?Intimidate
I'm probably going to leave on work time now thanks to this. Thank you.Precess
Thanks! In my case it was /etc/apache2/conf-available/security.conf that was denying the access.Curcio
H
12

WORKING Method { if there is no problem other than configuration }

By Default Appache is not restricting access from ipv4. (common external ip)

What may restrict is the configurations in 'httpd.conf' (or 'apache2.conf' depending on your apache configuration)

Solution:

Replace all:

<Directory />
     AllowOverride none
    Require all denied

</Directory>

with

<Directory />
     AllowOverride none
#    Require all denied

</Directory>

hence removing out all restriction given to Apache

Replace Require local with Require all granted at C:/wamp/www/ directory

<Directory "c:/wamp/www/">
    Options Indexes FollowSymLinks
    AllowOverride all
    Require all granted
#   Require local
</Directory>
Hoarhound answered 25/6, 2016 at 17:43 Comment(0)
U
3

Solution is just simple.

If you are trying to access server using your local IP address and you are getting error saying like Forbidden You don't have permission to access / on this server

Just open your httpd.conf file from (in my case C:/wamp/bin/apache/apache2.2.21/conf/httpd.conf)

Search for

<Directory "D:/wamp/www/"> .... ..... </Directory>

Replace Allow from 127.0.0.1

to

Allow from all

Save changes and restart your server.

Now you can access your server using your IP address

Underwing answered 10/6, 2016 at 11:31 Comment(0)
E
2

The problem lies in https.conf file!

# Virtual hosts
# Include conf/extra/httpd-vhosts.conf

The error occurs when hash(#) is removed or messed around with. These two lines should appear as shown above.

Ean answered 13/6, 2016 at 14:38 Comment(2)
Please format your answer.Stonefish
messed around with what?Hypogene
C
1

Found my solution on Apache/2.2.15 (Unix).

And Thanks for answer from @QuantumHive:

First: I finded all

Order allow,deny
Deny from all

instead of

Order allow,deny

Allow from all

and then:

I setted

#
# Control access to UserDir directories.  The following is an example
# for a site where these directories are restricted to read-only.
#
#<Directory /var/www/html>
#    AllowOverride FileInfo AuthConfig Limit
#    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
#    <Limit GET POST OPTIONS>
#        Order allow,deny
#        Allow from all
#    </Limit>
#    <LimitExcept GET POST OPTIONS>
#        Order deny,allow
#        Deny from all
#    </LimitExcept>
#</Directory>

Remove the previous "#" annotation to

#
# Control access to UserDir directories.  The following is an example
# for a site where these directories are restricted to read-only.
#
<Directory /var/www/html>
    AllowOverride FileInfo AuthConfig Limit
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    <Limit GET POST OPTIONS>
        Order allow,deny
        Allow from all
    </Limit>
    <LimitExcept GET POST OPTIONS>
        Order deny,allow
        Deny from all
    </LimitExcept>
</Directory>

ps. my WebDir is: /var/www/html

Cullender answered 1/6, 2017 at 4:15 Comment(0)
B
0

This works for me on Mac OS Mojave:

<Directory "/Users/{USERNAME}/Sites/project">
    Options +Indexes +FollowSymLinks +MultiViews
    AllowOverride All
    require all granted
</Directory>
Blend answered 4/11, 2018 at 22:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.