Apache FilesMatch指令以匹配请求的域 [英] Apache FilesMatch directive to match requested domain

查看:70
本文介绍了Apache FilesMatch指令以匹配请求的域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to setup the FilesMatch directive in such a way that when the user requests a resource that matches the domain name, only then will the resource be served.

例如:

example.com/example.com.html =好

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

example.com/other.com.html = not allowed, serves error.html instead

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

I'm currently considering configuring Apache like so:

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

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

But to achieve this effect I would need to have the domain of the request as a variable somehow.

任何建议表示赞赏.

推荐答案

此选项不仅检查文件是否存在,而且还检查文件是否与所需的模式匹配:

This option doesn't only check if the file exists, but also if it matches your desired pattern:

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

有更多的方法可以执行此操作,但是重写为您提供了最多(也许也是最强大)的选择.确实需要激活mod_rewrite.

There are more ways to do it, but rewriting gives you the most and probably also the most powerful options. It does require mod_rewrite to be activated though.

这篇关于Apache FilesMatch指令以匹配请求的域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆