使用 htaccess 重定向目录,但不重定向其中的文件

发布于 2024-10-04 15:23:09 字数 422 浏览 0 评论 0原文

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

Redirect /folder http://domain.com/

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

On my website, I've got a directory /folder with some images and html in it. I want to redirect users who try to access http://domain.com/folder to http://domain.com/ but don't want requests for the files in that directory to redirect to http://domain.com/ either. When I try

Redirect /folder http://domain.com/

it breaks the site because now it thinks all the images, etc are in the root directory when it is not. How do i fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简美 2024-10-11 15:23:09

使用 RedirectMatch 相反:

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

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

Use RedirectMatch instead:

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

Now the URI path must exactly match /folder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文