【发布时间】:2014-10-07 02:52:35
【问题描述】:
是的,又是一个 RewriteCond,但我正在努力让它发挥作用....
我的 Apache 根为 /var/www/html/,如果我转到 http://example.com/,它会正确使用 /var/www/html/index.php。
现在,问题是我在/var/www/images/example.com/ 中有图像。这是因为我有一个需要动态的多站点设置。 PHP 将整理出使用了哪个站点的代码,因此移动图像或为它们加上别名不是一种选择,因为它需要是动态的。
所以,我的/var/www/html/.htaccess 中有这样的内容:
Options -MultiViews -Indexes
RewriteEngine on
RewriteCond /var/www/images/example.com%{REQUEST_URI} -f
RewriteRule ^(.+)$ /var/www/images/example.com/$1 # <--- this DOES fire when the image exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /var/www/html/test.php?file=%{REQUEST_FILENAME} [END]
test.php 只是呼应$_GET,奇怪的是$_GET['file'] 是/var/www/html/var
我做错了什么?!
更新
好的,现在我有了这个:
RewriteCond %{REQUEST_URI} !^/sites/
RewriteRule ^(.*)$ sites/%{HTTP_HOST}/$1 [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php
我对其进行了更改,以便站点文件位于主服务器根目录中。现在我不能让它不允许直接访问文件。
我想要的是这个:
http://example.com/images/fb.png -> /var/www/sites/example.com/images/fb.png http://example.com/sites/example.com/images/fb.png -> /var/www/index.php(显示 404) http://example.com/whatever -> /var/www/index.php
如您所见,第二行文件是文件的完整直接路径,应该传递给 index.php,但它只是发送文件。如何防止这种情况发生?
【问题讨论】: