如何在 apache 配置中使用通配符别名作为文件名?

Posted

技术标签:

【中文标题】如何在 apache 配置中使用通配符别名作为文件名?【英文标题】:How can I use a wildcard alias for file names in apache config? 【发布时间】:2012-03-31 05:24:30 【问题描述】:

当调用以下任一 url 时,我需要 apache 调用 file.php

/file.xml /file-contents.xml /file-abc.xml /file-n.xml /file-xyz.xml

这是我的 apache conf 文件中的一个示例:(倒数第二行是关键行)

<VirtualHost *:80>
    DocumentRoot /html
    ServerName domain.com

    UseCanonicalName Off

    Alias /file.xml /html/file.php
    Alias /file-contents.xml /html/file.php
    Alias /file-*.xml /html/file.php
</VirtualHost>

我可以让 file.xml 和 file-contents.xml 调用 file.php 就好了。但通配符不起作用。

你有什么推荐的?


回答:

感谢马克 B!

AliasMatch ^/file-(.*).xml /html/file.php

【问题讨论】:

【参考方案1】:

AliasMatch 允许此类事情的正则表达式:http://httpd.apache.org/docs/2.0/mod/mod_alias.html#aliasmatch

【讨论】:

以上是关于如何在 apache 配置中使用通配符别名作为文件名?的主要内容,如果未能解决你的问题,请参考以下文章