Images disappears after REWRITE

Hi Everyone…I hope someone can help me…

I have two links and ReWrite rules for them. And the rules do change the links. But all the images including the background disappears.

This code

#/viewgallery.php?cname=Colorado-Fall to /photos/Colorado-Fall
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\\s/+viewgallery\\.php\\?cname=([^&\\s]+)
RewriteRule ^ /photos/%1/? [L,R=301]
RewriteRule ^photos/([^/]+)/?$ /viewgallery.php?cname=$1 [L,NC,QSA]

changes

http://www.xyz.com/viewgallery.php?cname=Colorado-Fall
to
http://www.xyz.com/photos/Colorado-Fall/

Then this

# /viewgallery.php?cname=Colorado-Fall&pcaption=Poked to /photos/Colorado-Fall/Poked.jpg
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\\s/+viewgallery\\.php\\?cname=([^&]+)&pcaption=([^&\\s]+)
RewriteRule ^ /photos/%1/%2/? [R=301,L]
RewriteRule ^photos/([^/]+)/([^.]+)/$ /viewgallery.php?cname=$1&pcaption=$2 [L,NC,NE]

changes the link

http://www.xyz.com/viewgallery.php?cname=Colorado-Fall&pcaption=Facing-Colors
to
http://www.xyz.com/photos/Colorado-Fall/Light-On-Fall-Colors/

What am I doing wrong here? I am using absolute paths in my PHP code.Like these…

"<a href=/viewgallery.php?cname=$cname&pcaption=".$caption_array[$next]."><img src=/photos/assets/left.png  border=0 ></a>";

yath,

That’s caused by changing the directory level with your redirection. Check my signature’s tutorial under the “Relative Links Are Missing!” section for the explanation and resolution.

Regards,

DK

DK this is what I have now in my head tag

<head>
<base href="http://www.xyz.com/"/>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<!-- <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"/> -->
<title>XYZ Site </title>
<link rel="stylesheet" type="text/css" href="/styles.css"/>
<link rel="shortcut icon" type="image/x-icon" href="/favicon1.0.ico"/>
</head>

DK thank you for your time…
But it still is not working. But in the process I found a strange behavior on the server.

I have a file - 1.jpg (I know it exist! )
But when I type in

http://www.xyz.com/photos/1.jpg

I get the message that “image is not found”.

BUT If I remove the Rewrite rules from the .htacces file I can view the image or any image!.
Doesn’t this mean my Rewrite rules are the root of the problem?

VERY strange! :eek: I think this is why I have the problem but not sure why!

Any ideas why this is happening?

Yath,

I believe that the <BASE> tag is supposed to reference the file (in which it exists), not the domain (or directory).

As for 1.jpg not being found, the mod_rewrite code you showed above will not affect it (as http://%HTTP_HOST}/1.jpg) so you’ll have to provide your entire .htaccess as well as the link to 1.jpg that you’re testing with.

BTW, good test (removing the mod_rewrite & testing the link) as that did narrow it down to the mod_rewrite.

Regards,

DK

The entire .htaccess code is

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

# /viewgallery.php?cname=Colorado-Fall&pcaption=Poked to /photos/Colorado-Fall/Poked.jpg
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\\s/+viewgallery\\.php\\?cname=([^&]+)&pcaption=([^&\\s]+)
RewriteRule ^ /photos/%1/%2/? [R=301,L]
RewriteRule ^photos/([^/]+)/([^.]+)/$ /viewgallery.php?cname=$1&pcaption=$2 [L,NC,NE]

#/viewgallery.php?cname=Colorado-Fall to /photos/Colorado-Fall
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\\s/+viewgallery\\.php\\?cname=([^&\\s]+)
RewriteRule ^ /photos/%1/? [L,R=301]
RewriteRule ^photos/([^/]+)/?$ /viewgallery.php?cname=$1 [L,NC]

The link to my site where 1.jpg is my background. The link to that is…

http://www.rajeevthomas.com/photos/1.jpg

Thank you for any help…

Yath

Yath,

While you’ve found the {THE_REQUEST} variable and have coded it correctly (I’d eliminate everything before the /{filename}), everything else seems pretty messed up. Therefore, before starting to examine and comment on your code, please let me recommend a thorough read of my signature’s tutorial.

Options +FollowSymLinks -MultiViews
# FollowSymLinks shouldn't be necessary
# Same with -MultiViews but, for this one, bettter safe than sorry!
# Turn mod_rewrite on
RewriteEngine On

# /viewgallery.php?cname=Colorado-Fall&pcaption=Poked to /photos/Colorado-Fall/Poked.jpg
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\\s/+viewgallery\\.php\\?cname=([^&]+)&pcaption=([^&\\s]+)
RewriteRule ^ /photos/%1/%2/? [R=301,L]

[indent]First, your original request is photos/1.jpg so {THE_REQUEST} will never match this RewriteCond's regex.[/indent]

RewriteRule ^photos/([^/]+)/([^.]+)/$ /viewgallery.php?cname=$1&pcaption=$2 [L,NC,NE]
# No escape???
# No Case is not applicable to {REQUEST_URI}s (its designed for {HTTP_HOST} which is NOT case sensitive

#/viewgallery.php?cname=Colorado-Fall to /photos/Colorado-Fall
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\\s/+viewgallery\\.php\\?cname=([^&\\s]+)
RewriteRule ^ /photos/%1/? [L,R=301]

[indent]Ditto AND RewriteRule will only match the EMPTY {REQUEST_URI}!?![/indent]
RewriteRule ^photos/([^/]+)/?$ /viewgallery.php?cname=$1 [L,NC]

Lots of criticism but not much help! However, I need a bit of explanation of WHY you’re trying to have viewgallery.php provide the image(s) and whether you want to force viewgallery to be displayed in lieu of photos/{filename}.

It seems as if you’re trying to perform something like the “Loopy Redirection” (“Redirect TO New Format” in the tutorial; what happens if you request viewgallery directly?). Better info, better coding help and explanation.

Regards,

DK

Criticism is much appreciated DK… I am going to start over, reading your tutorial. I honestly do not know much, I did this with the help of a friend. As far as I know when we tried to approach the viewgallery.php directly some images disappeared like the images for my ‘next’ and ‘previous’ buttons.

http://www.rajeevthomas.com/photos/Colorado-Journeys/Reflecting-On-Nature/

you will see the buttons here. But now, after the links are fixed with the .htaccess code above, those buttons are visible but all other images are gone!. :slight_smile:

The reason

WHY you’re trying to have viewgallery.php provide the image(s)
is that viewgallery.php is the core of the website. That file fetches the images files and information from database also produces the link.

and whether you want to force viewgallery to be displayed in lieu of photos/{filename}.

Are you asking if I want the word ‘viewgalley’ to be displayed on the link ?. No…I do not want that. The desired format is the format I have now ------> http://www.rajeevthomas.com/photos/Colorado-Journeys/Reflecting-On-Nature/ But the PROBLEM is that all the images disappeared now :rolleyes: , but the links look PERFECT :slight_smile:

Yath,

Both your links returned 404s without a 404 handler.

We’re sneaking up on your “specification” so let me give it a try:

If photo/{something} is requested, redirect to viewgallery.

If viewgallery is requested AND IS NOT A SUBREQUEST, redirect to photo.

# .htaccess in DocumentRoot

RewriteEngine on

# Redirect to "usable link"
RewriteRule ^photo/([-a-zA-Z]+)/$ viewgallery.php?cname=$1 [L]

# Redirect to NEW format
RewriteCond %{IS_SUBREQ} false
RewriteCond %{QUERY_STRING} cname=([-a-zA-Z]+)
RewriteRule ^viewgallery\\.php$ photo/%1/ [R=301,L]

The first RewriteRule will redirect photo/{whatever}/ to viewgallery.php with {whatever} as the value for cname. Of course, {whatever} consists only of -'s, a-z and A-Z (no digits or other characters).

If, however, the ORIGINAL request is to viewgallery, you need to get the value of the query string ({whatever}) before redirecting to photo/ AND make it a 301 (visible) redirection.

As for your links, be sure that you’re using photo/{whatever} (OR /photo/{whatever} if you’re linking from many directory levels).

Regards,

DK