views:

563

answers:

1

When I try to display image using image tag, there is problem to display image. For now images are in project/images/logo. The page where I am displaying image is in project/projectadmin/file.php.

The image path is given as below http://localhost/project/images/logo/cat%5F149.jpg. When i remove htaccess, then no problem to display image. Also when i use image path like this http://localhost/project/projectadmin/images/logo/cat%5F149.jpg moving images to project/projectadmin/images/logo/, no problem to display image.

What is my problem?

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]
A: 

Most likely you .htaccess file is using something like mod_rewrite to rewrite_urls. Then, when you go to grab an image, it is rewriting that URL to something like a PHP file.

Go to the IMG Address yourself and see what happens. You probably won't see an image either.

Probably the easiest fix to this is to check if the file exists. If so, don't redirect. Do that with:

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

So, you HTACCESS file would look like

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]

Note that will will allow access to any .php file directly, but that shouldn't matter considering you don't have any barrier to stop that in the first place.

Chacha102
Yeah i can not even upload image. So what can be the solution? Thank you Chacha102
Thank you so much Chacha102! I am really sorry that i forgot to add the line RewriteRule ^image viewpic.php [L,NC]. Actually it was not allowing to display the image. But i come to know about RewriteCond, thanks for that and sorry again.