繁体   English   中英

重定向访问.htaccess到另一个文件

[英]Redirect access to .htaccess to another file

我当时正在玩.htaccess文件,我想知道,完全出于好奇,是否可以将对.htaccess文件本身的访问重定向到另一个文件?

例:

使用者前往http://www.example.com/.htaccess

我希望将用户重定向到index.php?foo=bar

我尝试了以下方法:

Redirect 301 /.htaccess /index.php?foo=bar

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^((?s).*)$ index.php?foo=bar [QSA,L]
</IfModule>

这些方法可在任何其他文件上使用,但是.htaccess文件本身始终会导致显示403 Forbidden页面。

这可能吗? 如果没有,那为什么呢?

如果查看Web服务器的配置文件,则会发现一些指令,该指令阻止用户从浏览器访问.htaccess.htpasswd文件。 例如,如果我打开位于/etc/apache2/apache.conf apache配置,则可以看到以下几行:

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
# 
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

因此,您应该可以将以上内容更改为:

Order allow,deny
Allow from all

您还需要确保您对.htaccess文件具有正确的文件许可权,最后使用以下命令重新启动服务器:

sudo service apache2 restart

当然,执行上述操作并不是很安全。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM