my problem is that I want to deny the access to a folder but I can't. I've put a .htaccess
file in this folder with just these lines:
我的问题是我想拒绝访问文件夹,但我不能。我只在这些文件夹中放了一个.htaccess文件:
order deny,allow
deny from all
Any idea of what can be happening?
什么可以发生什么?
4 个解决方案
#1
11
I get it! It was due to the apache configuration. In my foo.conf
of sites-avaiables directory I had:
我知道了!这是由于apache配置。在我的foo.conf网站-avaiables目录中,我有:
AllowOverride None
As apache doc says, AllowOverride Description: Types of directives that are allowed in .htaccess files
正如apache doc所说,AllowOverride描述:.htaccess文件中允许的指令类型
When it is changed to:
当它改为:
AllowOverride All
it works perfectly! You can also configure it with specific options:
它完美地运作!您还可以使用特定选项对其进行配置:
AllowOverride directive-type
directive-options at: apache.org
指令选项:apache.org
#2
3
I had the same issue using that method. Try this instead:
我使用该方法时遇到了同样的问题。试试这个:
RewriteEngine On
RewriteCond %{REQUEST_URI} foldername
RewriteCond %{REMOTE_ADDR} !^111\.222\.333\.44$
RewriteRule . - [R=404,L]
With this method you need to add your own ip.
使用此方法,您需要添加自己的IP。
Options: instead of the last line being a 404 page not found:
选项:而不是最后一行是404页面未找到:
RewriteRule . - [R=404,L]
you can change it to a 403 forbidden:
您可以将其更改为403禁止:
RewriteRule .*? - [F]
or redirect to your homepage:
或重定向到您的主页:
RewriteRule . http://www.domain.com/ [R,L]
#3
1
you need to do two things,first, change the conf of apache to allow override, second, to change the conf of a hosting to allow override
你需要做两件事,首先,改变apache的conf以允许覆盖,第二,改变托管的conf以允许覆盖
first
第一
nano /etc/apache2/apache2.conf
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
and change it to;
并将其改为;
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Second
第二
cd /etc/apache2/sites-available
nano yourdomain.com.conf
add the following codes into it,
将以下代码添加到其中,
<Directory "/var/www/html/yourdomain.com/public_html">
AllowOverride All
Require all granted
</Directory>
after adding
添加后
<VirtualHost *:80>
ServerAdmin support@yourdomain.com
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/html/yourdomain.com/public_html/
<Directory "/var/www/html/yourdomain.com/public_html">
AllowOverride All
Require all granted
</Directory>
#4
0
Use this:
用这个:
<Directory /folder_name>
Order Deny,Allow
Deny from all
</Directory>
Its better to add a rule to allow your ip address. You can use allow from your_ip_address for this. Be careful with the ip address as it can be shared. You can check your ip address using http://www.whatismyip.com/
最好添加规则以允许您的IP地址。您可以使用from_ip_address中的allow来实现此目的。小心ip地址,因为它可以共享。您可以使用http://www.whatismyip.com/查看您的IP地址
#1
11
I get it! It was due to the apache configuration. In my foo.conf
of sites-avaiables directory I had:
我知道了!这是由于apache配置。在我的foo.conf网站-avaiables目录中,我有:
AllowOverride None
As apache doc says, AllowOverride Description: Types of directives that are allowed in .htaccess files
正如apache doc所说,AllowOverride描述:.htaccess文件中允许的指令类型
When it is changed to:
当它改为:
AllowOverride All
it works perfectly! You can also configure it with specific options:
它完美地运作!您还可以使用特定选项对其进行配置:
AllowOverride directive-type
directive-options at: apache.org
指令选项:apache.org
#2
3
I had the same issue using that method. Try this instead:
我使用该方法时遇到了同样的问题。试试这个:
RewriteEngine On
RewriteCond %{REQUEST_URI} foldername
RewriteCond %{REMOTE_ADDR} !^111\.222\.333\.44$
RewriteRule . - [R=404,L]
With this method you need to add your own ip.
使用此方法,您需要添加自己的IP。
Options: instead of the last line being a 404 page not found:
选项:而不是最后一行是404页面未找到:
RewriteRule . - [R=404,L]
you can change it to a 403 forbidden:
您可以将其更改为403禁止:
RewriteRule .*? - [F]
or redirect to your homepage:
或重定向到您的主页:
RewriteRule . http://www.domain.com/ [R,L]
#3
1
you need to do two things,first, change the conf of apache to allow override, second, to change the conf of a hosting to allow override
你需要做两件事,首先,改变apache的conf以允许覆盖,第二,改变托管的conf以允许覆盖
first
第一
nano /etc/apache2/apache2.conf
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
and change it to;
并将其改为;
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Second
第二
cd /etc/apache2/sites-available
nano yourdomain.com.conf
add the following codes into it,
将以下代码添加到其中,
<Directory "/var/www/html/yourdomain.com/public_html">
AllowOverride All
Require all granted
</Directory>
after adding
添加后
<VirtualHost *:80>
ServerAdmin support@yourdomain.com
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/html/yourdomain.com/public_html/
<Directory "/var/www/html/yourdomain.com/public_html">
AllowOverride All
Require all granted
</Directory>
#4
0
Use this:
用这个:
<Directory /folder_name>
Order Deny,Allow
Deny from all
</Directory>
Its better to add a rule to allow your ip address. You can use allow from your_ip_address for this. Be careful with the ip address as it can be shared. You can check your ip address using http://www.whatismyip.com/
最好添加规则以允许您的IP地址。您可以使用from_ip_address中的allow来实现此目的。小心ip地址,因为它可以共享。您可以使用http://www.whatismyip.com/查看您的IP地址