SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Location
    PT
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile RewriteCond - Grabbing Query With Multiple Regexp

    Hi!

    Currently I have this on my htaccess:

    Code:
    RewriteCond %{REQUEST_URI} c2/games.html
    RewriteCond %{QUERY_STRING} pg=([^&]+)
    RewriteRule .? c2p%1/games.html? [R=301,L]
    The above works fine, however I need something more dynamic, like the page is not always games.html and c2 is not always c2, it can be c1 or c2 etc...


    I've tried something like this:

    Code:
    RewriteCond %{REQUEST_URI} c([0-9]+)/([a-z-]+).html
    RewriteCond %{QUERY_STRING} pg=([0-9]+)
    RewriteRule .? c%1p%3/%2.html? [R=301,L]
    However this does not work.

    Can someone please help me getting this done?

    Many thanks in advance!
    Yesterday is history. Tomorrow is a mystery.
    Today is a gift, that's why it's called the Present.

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

    Your new mod_rewrite is rather convoluted and repeating the {REQUEST_URI} is not necessary:
    Code:
    RewriteCond %{QUERY_STRING} pg=([0-9]+)
    RewriteRule ^c([0-9]+)/([a-z-]+)\.html$ c$1p%1/$2.html? [R=301,L]
    Others: The trailing ? after the redirect KILLS the existing query string.

    Because the code was rather convoluted, I suspected a loop but this is prevented by the "p" in the "directory" of the redirect. Be advised that other mod_rewrite is likely required because this is not likely to be an existing directory/file combination.

    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
  •