【发布时间】:2018-07-25 22:05:31
【问题描述】:
我在 example.com 上有一个非常简单的 html 页面。它仅由以下index.html 组成:
<html>
<body style="background-color:black;">
<img src="images/picture1.jpg" alt="example" style="width:40%;">
</html>
当我转到 example.com 时,页面加载完全符合预期,但我想这样做,以便将对 example.com 的任何请求重定向到此首页(因此 example.com/catfood 将用户带到 example.com )。为此,我将以下内容添加到.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/
RewriteRule ^ / [R=301]
它可以正确重定向,但会破坏图像。我相信这种情况正在发生,因为对 example.com/images/picture1.jpg 的请求现在被重定向到索引页面,但我不确定我需要添加到我的 .htaccess 中以允许全面重定向同时发生仍在首页上加载此图像。
【问题讨论】:
标签: apache .htaccess http webserver