php and mod_rewrite?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • namemattersnot@msn.com

    php and mod_rewrite?

    ok. i give up. need help :)

    here's the rule:

    RewriteRule ^test/(.+)/(.*)$ /index.php$2

    if i request: http://localhost/test/keyword/?show=files it properly
    redirects me.

    NOW, if i change the rule to: RewriteRule ^test/(.+)/(.*)$
    /index.php$2&key =$1
    it stops working.

    i figured out that if i remove ? from $show=files and change the rule
    to redirect to /index.php?$2, then i can use &key=$1. but i want to
    figure out how to redirect the ?show=files request AND at the end add
    &key=$1

    thanks in advance!

  • balaji

    #2
    Re: php and mod_rewrite?

    hi hru? im balaji. i have one big problem. Full details of
    mod_rewrite() value in php with sample example give(plz) me. now one
    small idea but most of process i can undrstand plz help me. plz tell me
    soon .


    namemattersnot@ msn.com wrote:[color=blue]
    > ok. i give up. need help :)
    >
    > here's the rule:
    >
    > RewriteRule ^test/(.+)/(.*)$ /index.php$2
    >
    > if i request: http://localhost/test/keyword/?show=files it properly
    > redirects me.
    >
    > NOW, if i change the rule to: RewriteRule ^test/(.+)/(.*)$
    > /index.php$2&key =$1
    > it stops working.
    >
    > i figured out that if i remove ? from $show=files and change the rule
    > to redirect to /index.php?$2, then i can use &key=$1. but i want to
    > figure out how to redirect the ?show=files request AND at the end add
    > &key=$1
    >
    > thanks in advance![/color]

    Comment

    • Justin Koivisto

      #3
      Re: php and mod_rewrite?

      namemattersnot@ msn.com wrote:[color=blue]
      > ok. i give up. need help :)
      >
      > here's the rule:
      >
      > RewriteRule ^test/(.+)/(.*)$ /index.php$2
      >
      > if i request: http://localhost/test/keyword/?show=files it properly
      > redirects me.
      >
      > NOW, if i change the rule to: RewriteRule ^test/(.+)/(.*)$
      > /index.php$2&key =$1
      > it stops working.
      >
      > i figured out that if i remove ? from $show=files and change the rule
      > to redirect to /index.php?$2, then i can use &key=$1. but i want to
      > figure out how to redirect the ?show=files request AND at the end add
      > &key=$1[/color]

      RewriteRule does not match against the query string in mod_rewrite. To
      match against that you will need to use

      RewriteCond %{QUERY_STRING} pattern

      RewriteRule works against the REQUEST_URI..

      Therefore, as per your examples above:

      RewriteRule ^test/(.+)/(.*)$ /index.php$2&key =$1

      Consider this URI:
      /test/dir1/dir2/?var=val

      The result would be:
      /index.phpdir2/&dir1

      If you want to keep the original query string with your request, add the
      [QSA] flag at the end of the RewriteRule statement (Query String Append)..

      Using this with the same URI above...
      RewriteRule ^test/([^/]+)/([^/]+)$ index.php?$2&ke y=$1 [QSA]

      /index.php?dir2& key=dir1&var=va l

      HTH

      --
      Justin Koivisto, ZCE - justin@koivi.co m

      Comment

      • namemattersnot@msn.com

        #4
        Re: php and mod_rewrite?

        Justin,

        Thank you for your elaborate answer. Perhaps im not doing something
        right, but here is what I get:

        [Thu Feb 02 11:08:15 2006] [error] [client 127.0.0.1] File does not
        exist: D:/system_programs/xampp/htdocs/gallery

        This is in response to my request:



        That sould be processed with this rule:

        RewriteRule ^gallery/([^/]+)/([^/]+)$ /index.php?$2&ga llery_name=$1
        [QSA]

        :) why?

        P.S. Tried on my Apache server on a linux box - same result.

        Comment

        • Justin Koivisto

          #5
          Re: php and mod_rewrite?

          namemattersnot@ msn.com wrote:[color=blue]
          > Justin,
          >
          > Thank you for your elaborate answer. Perhaps im not doing something
          > right, but here is what I get:
          >
          > [Thu Feb 02 11:08:15 2006] [error] [client 127.0.0.1] File does not
          > exist: D:/system_programs/xampp/htdocs/gallery
          >
          > This is in response to my request:
          >
          > http://localhost/gallery/galleryname...how_per_page=5
          >
          > That sould be processed with this rule:
          >
          > RewriteRule ^gallery/([^/]+)/([^/]+)$ /index.php?$2&ga llery_name=$1
          > [QSA]
          >
          > :) why?[/color]

          ^gallery/([^/]+)/([^/]+)$
          match REQUEST_URI that:
          * starts with literal "gallery/"
          * followed by one or more characters that are not "/"
          * followed by a "/"
          * ends with one or more characters that are not "/"

          Your request:
          gallery/galleryname/
          * starts with literal "gallery/"
          * followed by one or more characters that are not "/"
          * followed by a "/"
          * DOES NOT end with one or more characters that are not "/"

          You can modify the rule to accept this, or create a second rule, I opt
          for modification:

          RewriteRule ^gallery/([^/]+)(/([^/]+))?$ /index.php?$3&ga llery_name=$1 [QSA]

          HTH

          --
          Justin Koivisto, ZCE - justin@koivi.co m

          Comment

          • namemattersnot@msn.com

            #6
            Re: php and mod_rewrite?

            still doesn't work :(

            after playing around, i found this to work:

            RewriteRule ^gallery/([^/]+)/(.*)$ /index.php?galle ry_name=$1$2 [QSA]

            However, if my query string is
            "mAIJX1CKDGM6nD Kq/QUfPXMxIKOrTdZQ rPcxAdM/DeJKhH9cycqCJrj ZsKgOePSF"
            (that is, it contains "/"), then it's not interpreted properly. and i
            believe it's my regex syntax in mode_rewrite.

            This is simply a headache :) I spent so many hours on this one rule.
            ouch. any ideas?

            Thanks!

            Comment

            • namemattersnot@msn.com

              #7
              Re: php and mod_rewrite?

              RewriteRule ^gallery/([^/]+)/$

              worked.

              Comment

              Working...