SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Can't get my Simple rewrite to work

    We changed the software/script on my site.

    The pages and links are different, we do still use the same id's, here is the real-world example:

    Old script:
    http://www.mysite.com/photos/details...image_id=53974
    http://www.mysite.com/photos/categories.php?cat_id=750

    New script:
    http://www.mysite.com/album.php?yr=2009&aid=0750

    The only thing that is important here is the old "cat_id", which is now "aid", the number is the same (750 in this case) but since we're now using 4 digits, there needs to be an extra 0 for this, which I added. However, I can't get it to work...
    I've placed this in the root (/) of my site.
    The old script had 2 different pages, a details page and a categories page, both had the cat_id. The image_id from the details.php can be ignored, this can be redirected to the new album.php with the "aid".

    Can anyone spot my fault(s) ?

    PHP Code:
    RewriteEngine On
    Options 
    +FollowSymLinks 
    Redirect 
    ^photos/categories\.php\?cat_id=([0-9]+)$ http://www.mysite.com/album.php?yr=2009&aid=0$1 

    ThanQ Everyone !

  2. #2
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I also did:
    RewriteRule ^photos/categories.php?cat_id=([0-9]+)$ http://www.mysite.com/album.php?yr=2009&aid=0$1

    No Luck...

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    cb,

    Back to the tutorial, my friend! I don't believe Redirect(Match) can examine the query string just like a RewriteRule can't (it can only attempt to match the {REQUEST_URI} string). THEREFORE, you MUST use RewriteCond to examine (and capture) from the query string for your redirects.

    If you can't get the answer you need from those hints, come back and I'll lead you through it (I don't code for free but am willing to spend the time to help members LEARN about 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

  4. #4
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No luck yet...

    PHP Code:
    RewriteCond %{QUERY_STRING} !marker  
    RewriteCond 
    %{QUERY_STRINGaid=([-a-zA-Z0-9_+]+)  
    RewriteRule ^/?album\.php$ %1? [R=301,L]  
     
    RewriteRule ^/?photos/categories\.php\?cat_id=([-a-zA-Z0-9_+]+)$ http://www.partypixsuriname.com/album.php?yr=2009&aid=0$1 [L] 

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    cb,

    I don't understand your use of the !marker test. What's that for?

    No matter, it shouldn't play a part (unless 'marker' is in your query string).

    THEN, what's with trying to redirect album.php to the value of aid? that will NOT work (unless aid is a filename in your DocumentRoot)!

    FINALLY, you fall back on trying to test/capture a value in a query string using a RewriteRule. That will NEVER work (as explained above, a RewriteRule can ONLY examine the {REQUEST_URI} string which, by definition, does NOT include the {QUERY_STRING}). You have the correct approach in your RewriteCond statements in the first mod_rewrite block; why did you abandon that? Do the same thing in the second mod_rewrite block BUT do not use the full absolute URL, only the URI (or the redirection will be displayed - if you WANT it displayed, use R=301 so SEs know it's a permanent redirection).

    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


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
  •