今天我想做的就是将重定向规则写入子文件夹,例如: 您输入 URL:example.com,您将被重定向到 example.com/subfolder
多么简单的愿望。我试图在互联网上找到解决方案。互联网告诉我在 htdocs 根目录中添加一个 .htaccess 文件:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ subfolder [L]
我就是这么做的。但显然没有成功,他们没有告诉我必须在 httpd.conf 中取消注释该模块:
LoadModule rewrite_module modules/mod_rewrite.so
所以我也这么做了。再次没有成功。他们没有告诉我必须更改 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>
再次没有成功,因为我在输入 URL 时收到此错误:
Forbidden You don't have permission to access / on this server.
现在我陷入困境,在互联网上找不到更多解决方案。出于私有(private)原因,我只是在 Windows 7 计算机上运行 Apache 2.4。
最佳答案
感谢 Error with .htaccess and mod_rewrite 找到了我的解决方案
对于 Apache 2.4 以及所有 *.conf 文件(例如 httpd-vhosts.conf、http.conf、httpd-autoindex.conf ..etc),请使用
Require all granted
而不是
Order allow,deny
Allow from all
Order 和 Allow 指令在 Apache 2.4 中已弃用。
关于apache - 禁止访问您无权访问/在此服务器上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21551840/