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
我今天想做的就是将一个重定向规则写入子文件夹,例如:输入URL: example.com,然后重新定向到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:
这样一个简单的愿望。我试图在网上找到一个解决方案。互联网让我在htdocs的根中添加一个.htaccess文件:
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:
我做了这个。但显然没有成功,他们没有告诉我,我必须取消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:
我也这么做了。又没有成功。他们没有告诉我必须改变我的httpd。conf使.htaccess文件被启用:
<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:
同样没有成功,因为我在输入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.
现在我陷入了困境,在互联网上找不到更多的解决方案。出于私人原因,我只是在我的Windows 7机器上运行Apache 2.4。
5 个解决方案
#1
149
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
找到我的解决方案,这要感谢对Apache 2.4和所有*的.htaccess和mod_rewrite的错误。conf文件(例如httpd-vhosts。相依,http。相依,httpd-autoindex。conf . .等)使用
Require all granted
instead of
而不是
Order allow,deny
Allow from all
The Order and Allow directives are deprecated in Apache 2.4.
在Apache 2.4中,命令和允许指令被弃用。
#2
11
WORKING Method { if there is no problem other than configuration }
工作方法{如果没有问题,除了配置}
By Default Appache is not restricting access from ipv4. (common external ip)
默认情况下Appache不限制ipv4的访问。(常见的外部ip)
What may restrict is the configurations in 'httpd.conf' (or 'apache2.conf' depending on your apache configuration)
可能限制的是“httpd”中的配置。相依”(或“输入。conf'依赖于您的apache配置)
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
因此取消了对Apache的所有限制。
Replace Require local
with Require all granted
at C:/wamp/www/
directory
替换需要在C:/wamp/www/目录下的所有请求。
<Directory "c:/wamp/www/">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
# Require local
</Directory>
#3
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
如果你试图使用你的本地IP地址访问服务器,你会得到错误的提示,比如你没有权限访问这个服务器。
Just open your httpd.conf file from (in my case C:/wamp/bin/apache/apache2.2.21/conf/httpd.conf
)
打开你的httpd。conf文件(在我的例子中是C:/wamp/bin/apache/apache2.2.21/conf/httpd.conf)
Search for
搜索
<Directory "D:/wamp/www/"> .... ..... </Directory>
<目录" d: 里面 www "> .... .....< /目录>
Replace Allow from 127.0.0.1
替换允许来自127.0.0.1
to
来
Allow from all
允许从所有
Save changes and restart your server.
保存更改并重新启动服务器。
Now you can access your server using your IP address
现在您可以使用您的IP地址访问您的服务器。
#4
1
The problem lies in https.conf file!
问题在于https。配置文件!
# 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.
当散列(#)被删除或混乱时出现错误。这两条线应该如上所示。
#5
1
Found my solution on Apache/2.2.15 (Unix).
在Apache/2.2.15 (Unix)上找到了我的解决方案。
And Thanks for answer from @QuantumHive:
感谢@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
我的WebDir是:/var/www/html。
#1
149
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
找到我的解决方案,这要感谢对Apache 2.4和所有*的.htaccess和mod_rewrite的错误。conf文件(例如httpd-vhosts。相依,http。相依,httpd-autoindex。conf . .等)使用
Require all granted
instead of
而不是
Order allow,deny
Allow from all
The Order and Allow directives are deprecated in Apache 2.4.
在Apache 2.4中,命令和允许指令被弃用。
#2
11
WORKING Method { if there is no problem other than configuration }
工作方法{如果没有问题,除了配置}
By Default Appache is not restricting access from ipv4. (common external ip)
默认情况下Appache不限制ipv4的访问。(常见的外部ip)
What may restrict is the configurations in 'httpd.conf' (or 'apache2.conf' depending on your apache configuration)
可能限制的是“httpd”中的配置。相依”(或“输入。conf'依赖于您的apache配置)
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
因此取消了对Apache的所有限制。
Replace Require local
with Require all granted
at C:/wamp/www/
directory
替换需要在C:/wamp/www/目录下的所有请求。
<Directory "c:/wamp/www/">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
# Require local
</Directory>
#3
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
如果你试图使用你的本地IP地址访问服务器,你会得到错误的提示,比如你没有权限访问这个服务器。
Just open your httpd.conf file from (in my case C:/wamp/bin/apache/apache2.2.21/conf/httpd.conf
)
打开你的httpd。conf文件(在我的例子中是C:/wamp/bin/apache/apache2.2.21/conf/httpd.conf)
Search for
搜索
<Directory "D:/wamp/www/"> .... ..... </Directory>
<目录" d: 里面 www "> .... .....< /目录>
Replace Allow from 127.0.0.1
替换允许来自127.0.0.1
to
来
Allow from all
允许从所有
Save changes and restart your server.
保存更改并重新启动服务器。
Now you can access your server using your IP address
现在您可以使用您的IP地址访问您的服务器。
#4
1
The problem lies in https.conf file!
问题在于https。配置文件!
# 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.
当散列(#)被删除或混乱时出现错误。这两条线应该如上所示。
#5
1
Found my solution on Apache/2.2.15 (Unix).
在Apache/2.2.15 (Unix)上找到了我的解决方案。
And Thanks for answer from @QuantumHive:
感谢@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
我的WebDir是:/var/www/html。