【问题标题】:Apache - Mapping url to local path for static contentApache - 将 url 映射到静态内容的本地路径
【发布时间】:2011-10-07 21:13:36
【问题描述】:

我的 httpd.conf

<VirtualHost *:80>
    ...
    DocumentRoot /home/www/static
    ...
    <Directory /home/www/static>
    Order Allow,Deny
    Allow from all
    </Directory>

    <Location "/foo">
    SetHandler None
    </Location>
</virtualhost>

我在 /home/www/static/foo/helloworld.txt 有一个文件。如果我去http://localhost/foo/helloworld.txt 我会看到那个文件。

现在,出于某种不相关的原因,我想更改网址。上面的 url 应该什么都不返回,而 http://localhost/bar/helloworld.txt 应该返回文件。我想实现这一点,而无需更改目录结构中的任何内容。

这是怎么做到的?

【问题讨论】:

    标签: apache url static


    【解决方案1】:

    您可以使用Alias 将不同的 url 路径映射到文件系统路径:

    Alias /bar /home/www/static/foo
    

    请参阅http://httpd.apache.org/docs/2.2/mod/mod_alias.html#alias 了解更多信息。

    【讨论】:

    • 或者你可以创建一个符号链接bar指向/home/www/static/foo
    猜你喜欢
    • 2015-07-03
    • 2011-02-14
    • 2015-12-17
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 2015-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多