SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mod-rewrite rules acting as the same

    I want to use PHP to show either 'Added', or 'Edited' depending on the url. However, either adding or editing both show 'Added'. Seems that Apache is seeing the added rule as the rule for both, or it's stopping after added.

    How can I make the two different?

    RewriteRule ^movies/([a-zA-Z0-9\-]+)\/([a-zA-Z0-9\-]+) tags/index.php?title=$1&added=$2

    RewriteRule ^movies/([a-zA-Z0-9\-]+)\/([a-zA-Z0-9\-]+) tags/index.php?title=$1&updated=$2

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Your rules (URLs) are the same, so how would it know which URLs are "added" and which are "edited"?

  3. #3
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    Your rules (URLs) are the same, so how would it know which URLs are "added" and which are "edited"?
    how are they the same? One says added, one says edited. Does that not matter?

  4. #4
    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)
    tg,

    Dan is correct. Apache has no way to differentiate between the two bits of regex code (it'll match the first every time) when you merely repeat movies/([a-zA-Z0-9\-]+)\/([a-zA-Z0-9\-]+) for both (the red bits are also in error - no need to escape these). That means that the first RewriteRule must be matched AND REDIRECTED before the second RewriteRule gets to see the {REQUEST_URI} string.

    Differentiate!

    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 Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is where I'm stumped.

    The actual urls are
    tags/index.php?id=$id&updated=true
    tags/index.php?id=$id&added=true

    How do I differentiate?
    I thought I was by having added & updated?

  6. #6
    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)
    tg,

    It's NOT the redirection URIs that you have to worry about but the URIs to be matched by the regex. WHAT URIs (internal links) are you using (trying to redirect)? If you tell us more (including which version of Apache - it does make a difference!), we can actually help you through this!

    Of course, a quick read through the tutorial article linked in my signature could cut through all this preliminary nonsense and get you on the right track, too (and probably give you the code you need)!

    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
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    tg,

    It's NOT the redirection URIs that you have to worry about but the URIs to be matched by the regex. WHAT URIs (internal links) are you using (trying to redirect)? If you tell us more (including which version of Apache - it does make a difference!), we can actually help you through this!

    Of course, a quick read through the tutorial article linked in my signature could cut through all this preliminary nonsense and get you on the right track, too (and probably give you the code you need)!

    Regards,

    DK
    Before I originally posted I took a look at your tutorials. I'm using Safari 3 and couldn't see a thing. When I clicked (click to show/hide text) all I saw was (hide this text). When I clicked that nothing happened.

    Here's what I have

    real page: /tags/index.php?title=$title&updated=true (if I remove the htaccess file, this works)

    Link in HTML source code: /movies/$title/updated/');

    regex: ^movies/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+) tags/index.php?title=$1&updated=$2[L]

    I have this working for a few other redirects to the exact same page. no problem. If I remove the added or updated it works.

  8. #8
    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)
    tg,

    First, looking into a Safari problem is low priority (I've been wrapped up moving websites OFF a Site5 server 'cause they force use of a shared mail server AND they allow spammers - I need to NOT have my e-mail blocked) but SitePoint has a version of my tutorial online at http://www.sitepoint.com/article/apa...write-examples.

    Then, your regex does NOT match the link you show - where is the trailing /? My favorite bug-a-boo, specificity, would help you if that second atom is either updated or added (and a better key is recommended):
    Code:
    RewriteEngine on
    RewriteRule ^movies/([a-zA-Z0-9\-]+)\/(added|updated)/? tags/index.php?title=$1&$2=$2 [L]
    Don't forget the Last flag, too!

    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

  9. #9
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    tg,

    First, looking into a Safari problem is low priority (I've been wrapped up moving websites OFF a Site5 server 'cause they force use of a shared mail server AND they allow spammers - I need to NOT have my e-mail blocked) but SitePoint has a version of my tutorial online at http://www.sitepoint.com/article/apa...write-examples.

    Then, your regex does NOT match the link you show - where is the trailing /? My favorite bug-a-boo, specificity, would help you if that second atom is either updated or added (and a better key is recommended):
    Code:
    RewriteEngine on
    RewriteRule ^movies/([a-zA-Z0-9\-]+)\/(added|updated)/? tags/index.php?title=$1&$2=$2 [L]
    Don't forget the Last flag, too!

    Regards,

    DK
    That got it!
    Funny. It's always the little things (like not paying attention) that'll get you.

    Thank you very much. And thanks for the link. I've bookmarked it

  10. #10
    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)
    tg,

    No problem! I'm glad that I was able to help you to get it working!

    (I hope you noted that I used $2=$2 in the new query string, i.e., added=added or updated=updated - I'm not sure that's what your script is looking for but you should be able to deal with that.)

    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

  11. #11
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    tg,

    No problem! I'm glad that I was able to help you to get it working!

    (I hope you noted that I used $2=$2 in the new query string, i.e., added=added or updated=updated - I'm not sure that's what your script is looking for but you should be able to deal with that.)

    Regards,

    DK
    I noticed that immediately. Very clever.
    I was able to take that and apply it to another rule of the same type, yet with 4 parameters. You've cleared away some smoke for me

  12. #12
    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)
    tg,

    Yay! I'm glad we're smokin' now!

    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
  •