regex - mod_alias AliasMatch Regex - 匹配文件夹中除两种模式之外的所有内容?

标签 regex alias mod-alias

我想使用 AliasMatch 为文件夹中的所有内容创建别名,除了两个(或更多)特定正则表达式模式。

例如,以下 AliasMatch 为“content”文件夹中的所有内容创建别名:

AliasMatch /content(.*) /home/username/public_html/$1

但是有两个正则表达式模式我不想让上面的别名匹配,例如:

^content/([a-zA-Z0-9_-]+)/id-([a-zA-Z0-9_-]+)/([0-9]+)
^content/([a-zA-Z0-9_-]+)/nn-([a-zA-Z0-9_-]+)

我知道 NOT (!) 字符可用于否定模式,但我不知道如何在此处使用它,或者如何在 AliasMatch 中否定多个模式。

这是怎么做到的?

最佳答案

ModAlias 实际上支持否定前瞻。我在我的网站上使用它,效果很好:

AliasMatch ^/(?!w/|BingSiteAuth\.xml$|favicon\.ico$|google.{16}\.html$|robots\.txt$) /path/to/file

请确保您的正则表达式以“/”开头,因为它始终是 mod_alias 的第一个字符!切勿尝试先行开始您的规则,否则解析将失败。

关于regex - mod_alias AliasMatch Regex - 匹配文件夹中除两种模式之外的所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1352920/

相关文章:

MySQL LEFT 连接别名问题

regex - 为什么在 htaccess 正则表达式中使用双斜线点(即 :\\. )?

python - 在 python 正则表达式中,为什么 (h)* 和 (h)+ 不能产生相同的结果?

regex - 如何仅计算数字长度正则表达式

git - 我的 git 别名存储在哪里?

syntax-error - Joomla Seblod cck 相同的别名错误

java - 非捕获组中的捕获组

JavaScript 正则表达式 : repeating non-capturing group

.htaccess - 如何使用 htaccess 重定向除一个子目录之外的所有子目录

apache - Apache禁止使用Alias 403