【问题标题】:Problem in image display using htaccess使用 htaccess 显示图像的问题
【发布时间】:2009-08-17 04:30:04
【问题描述】:

当我尝试使用图像标签显示图像时,显示图像出现问题。目前图像位于项目/图像/徽标中。我显示图像的页面位于 project/projectadmin/file.php 中。

图片路径如下http://localhost/project/images/logo/cat_149.jpg。当我删除 htaccess 时,显示图像没问题。此外,当我使用这样的图像路径http://localhost/project/projectadmin/images/logo/cat_149.jpg 将图像移动到项目/projectadmin/images/logo/ 时,显示图像没问题。

我的问题是什么?

RewriteEngine On 
ReWriteBase /project 
RewriteRule ^(cat|Home|index.htm|)$ index.php [L,NC] 
RewriteRule ^signin/(.*)$ Login.php?a=$1 [L,NC] 
RewriteRule ^create_account/(.*)/(.*)$ createacc.php?v1=$1&v2=$2 [L,NC] 
RewriteRule ^signup/(.*)$ createacc.php?var1=$1&var2=$1&var3=signup [L,NC]
RewriteRule ^myhope/(.*)$ home.php?var11=$1 [L,NC] 
RewriteRule ^edit_account/(.*)$ edit_account.php?var12=$1 [L,NC] 
RewriteRule ^edit_account_ship_pr edit_account_ship.php [L,NC] 
RewriteRule ^edit_account_b/(.*)$ editacc.php?action=$1 [L,NC] 

【问题讨论】:

  • htaccess 文件中有什么??

标签: apache .htaccess mod-rewrite


【解决方案1】:

您的 .htaccess 文件很可能正在使用 mod_rewrite 之类的东西来 rewrite_urls。然后,当你去抓取一张图片时,它会将该 URL 重写为类似 PHP 文件的东西。

自己去 IMG 地址看看会发生什么。您可能也看不到图像。

可能最简单的解决方法是检查文件是否存在。如果是这样,请不要重定向。这样做:

RewriteCond %{SCRIPT_FILENAME} -f
RewriteCond %{SCRIPT_FILENAME} -d

所以,你的 HTACCESS 文件看起来像

RewriteEngine On 
ReWriteBase /project 

RewriteCond %{SCRIPT_FILENAME} -f
RewriteCond %{SCRIPT_FILENAME} -d

RewriteRule ^(cat|Home|index.htm|)$ index.php [L,NC] 
RewriteRule ^signin/(.*)$ Login.php?a=$1 [L,NC] 
RewriteRule ^create_account/(.*)/(.*)$ createacc.php?v1=$1&v2=$2 [L,NC] 
RewriteRule ^signup/(.*)$ createacc.php?var1=$1&var2=$1&var3=signup [L,NC]
RewriteRule ^myhope/(.*)$ home.php?var11=$1 [L,NC] 
RewriteRule ^edit_account/(.*)$ edit_account.php?var12=$1 [L,NC] 
RewriteRule ^edit_account_ship_pr edit_account_ship.php [L,NC] 
RewriteRule ^edit_account_b/(.*)$ editacc.php?action=$1 [L,NC]

请注意,这将允许直接访问任何 .php 文件,但考虑到您一开始没有任何障碍可以阻止它,这并不重要。

【讨论】:

  • 是的,我什至无法上传图片。那么有什么解决办法呢?谢谢Chacha102
  • 非常感谢Chacha102!很抱歉我忘记添加 RewriteRule ^image viewpic.php [L,NC] 行。实际上它不允许显示图像。但我开始了解 RewriteCond,谢谢,再次抱歉。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-20
  • 2020-09-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多