【问题标题】:Apache FilesMatch directive to match requested domainApache FilesMatch 指令以匹配请求的域
【发布时间】:2017-04-06 13:36:13
【问题描述】:

我正在尝试以这样一种方式设置 FilesMatch 指令,即当用户请求与域名匹配的资源时,才会提供该资源。

例如:

example.com/example.com.html = 好

example.com/other.com.html = 不允许,改为提供error.html

我目前正在考虑像这样配置 Apache:

<FilesMatch regexp+domain_name+regexp>
    allow the resource...
</FilesMatch>

但要达到这种效果,我需要以某种方式将请求的域作为变量。

任何建议表示赞赏。

【问题讨论】:

    标签: apache url configuration


    【解决方案1】:

    此选项不仅检查文件是否存在,还检查它是否与您想要的模式匹配:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_FILENAME} ^%{SERVER_NAME}\.html$
    RewriteRule ^ - [F]
    

    有更多方法可以做到这一点,但重写为您提供了最多,可能也是最强大的选择。不过,它确实需要激活mod_rewrite

    【讨论】:

    • 你“不接受”我的回答?!这有点令人惊讶...您能给出一些反馈,以便我可以修复它吗?
    猜你喜欢
    • 2012-08-26
    • 2010-10-26
    • 2012-09-06
    • 2011-09-26
    • 2015-01-02
    • 2014-11-07
    • 1970-01-01
    • 1970-01-01
    • 2010-10-31
    相关资源
    最近更新 更多