SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Mar 2010
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

    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

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

    Code:
    # /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

    Code:
    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..

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

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2010
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    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

    Code:
    <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
    Code:
    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! I think this is why I have the problem but not sure why!

    Any ideas why this is happening?

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2010
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thank you DK...

    The entire .htaccess code is

    Code:
    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

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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.

    Code:
    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]
    
    
    First, your original request is photos/1.jpg so {THE_REQUEST} will never match this RewriteCond's regex.
    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]
    Ditto AND RewriteRule will only match the EMPTY {REQUEST_URI}!?!
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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.

    Code:
    # .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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •