【问题标题】:Using htaccess to redirect a directory, but not the files in it使用 htaccess 重定向目录,但不重定向其中的文件
【发布时间】:2011-05-16 22:38:28
【问题描述】:

在我的网站上,我有一个目录/文件夹,其中包含一些图像和 html。我想将尝试访问http://domain.com/folder 的用户重定向到http://domain.com/,但也不希望对该目录中文件的请求重定向到http://domain.com/。当我尝试时

Redirect /folder http://domain.com/

它破坏了站点,因为现在它认为所有图像等都在根目录中,而实际上并非如此。我该如何解决这个问题?

【问题讨论】:

  • 你为什么要这样做?为了防止用户看到该文件夹​​的内容(使用 mod_autoindex)?因为如果是这种情况,那么您也可以关闭它的索引(使用Options -Indexes,有关更多信息,请参阅httpd.apache.org/docs/2.0/mod/core.html#options)...

标签: html apache .htaccess redirect


【解决方案1】:

改用RedirectMatch

RedirectMatch ^/folder$ http://example.com/

现在 URI 路径必须与 /folder 完全匹配。

【讨论】:

    猜你喜欢
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-23
    • 1970-01-01
    相关资源
    最近更新 更多