SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: URL rewrite issue

  1. #1
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    URL rewrite issue

    I'm having trouble with a rewrite issue i thought i had working.

    Code:
    RewriteRule (.*)/(.*)-(.*)\.html$ details.php?name=$2&storeID=$3
    RewriteRule (.*)/(.*)-(.*)-(.*)\.html$ details.php?name=$2&storeID=$3&cmspage=$4
    RewriteRule (.*)/(.*)-(.*)\.html$ details.php?name=$2&storeID=$3 --? works with: www.domain.com/details/name_of_page_here-72.html

    this doesn't work it defaults to the above
    RewriteRule (.*)/(.*)-(.*)-(.*)\.html$ details.php?name=$2&storeID=$3&cmspage=$4 --> http://www.domain.com/details/name_o...2-NewPage.html

    Output should give me
    Array
    (
    [name] => name_of_page_here
    [storeID] => 78409
    [cmspage] => NewPage

    )
    Sr. Website Developer and Internet Marketing
    www.CarlosJa.com
    Note: If anyone needs to get ahold of me please feel free to email me through my site. Apparently i missed quite a few private messages.

  2. #2
    SitePoint Guru bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    705
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Remember that .* captures everything, including hyphens. That's why your first rule matches your second scenario, because all it needs is at least one hyphen somewhere in the filename. I would try this:

    RewriteRule (.*)/([^/\-]+)-([^/\-]+)\.html$ details.php?name=$2&storeID=$3
    RewriteRule (.*)/([^/\-]+)-([^/\-]+)-([^/\-]+)\.html$ details.php?name=$2&storeID=$3&cmspage=$4

    [^/\-] means match any character that is not a slash (to ensure you stay within the current path segment) or a hyphen (to ensure to capture only the segment of the filename between hyphens.
    "Folks who know what they're doing make complexity seem simple."

  3. #3
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cool.. i understand.. thanks
    Sr. Website Developer and Internet Marketing
    www.CarlosJa.com
    Note: If anyone needs to get ahold of me please feel free to email me through my site. Apparently i missed quite a few private messages.

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
  •