【发布时间】:2014-04-14 14:43:34
【问题描述】:
我有一个使用 资源标签(图像、css、脚本)的静态 HTML 站点,如下所示:
<html>
<head><title>htaccess test page</title></head>
<body>
<img src="/img/img.jpg" alt="...">
</body>
</html>
当我在浏览器中加载 html 文件时,请求是:
http://localhost/img/img.jpg(可以理解地返回 404)
我希望向哪里提出请求:
http://localhost/site/img/img.jpg
目录结构如下:
- www
- site
- .htaccess
- img
- img.jpg
我一直在寻找解决方案,并且模糊地认为 RewriteCond 是可行的方法,但我无法让它发挥作用:
RewriteEngine On
# if requested URI is not a file
RewriteCond %{REQUEST_FILENAME} !-f
# serve the file from the img directory, yes, very limited,
# and requires me to add rules for scripts, css etc.
RewriteRule ^(.*)$ img/$1 [L]
任何帮助将不胜感激。 SO 为这个问题返回了很多解决方案,但它们似乎都不起作用。
【问题讨论】: