SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mod_rewrite question

    I'd like to use a question mark in variables

    For example,

    book.php?author=John_Dow&name=How_can_I_do_that?

    but when I use this string in my .htaccess:

    RewriteRule ([^/]+)/([^/]+).html book.php?author=$1&name=$2 [L]

    it doesn't work. Mod_Rewrite gurus, please help - how can I use question marks in variables?

  2. #2
    King of da Wackos Nintendo's Avatar
    Join Date
    Nov 2003
    Location
    Planet Zeekois
    Posts
    1,182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.*)/(.*)\.html$ book.php?author=$1&name=$2 [L]
    ...

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, Nintendo.
    But this doens't work in a case of question marks

  4. #4
    King of da Wackos Nintendo's Avatar
    Join Date
    Nov 2003
    Location
    Planet Zeekois
    Posts
    1,182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now I see. Some pages have a SECOND ? in them! Try.....

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.*)/(.*)\.html$ book.php?author=$1&name=$2? [L]
    RewriteRule ^(.*)/(.*)\.html$ book.php?author=$1&name=$2 [L]

    I think the ? will be taken out of the non_mod_rewrited URL. If the link needs the ? in the URL, try

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.*)/(.*)\?\.html$ book.php?author=$1&name=$2? [L]
    RewriteRule ^(.*)/(.*)\.html$ book.php?author=$1&name=$2 [L]
    ...

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's now working too

  6. #6
    King of da Wackos Nintendo's Avatar
    Join Date
    Nov 2003
    Location
    Planet Zeekois
    Posts
    1,182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Making the script take the ? out of the link might be the only way to make it work.
    ...

  7. #7
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Try running the links through urlencode before printing them to the page.
    Mike
    It's not who I am underneath, but what I do that defines me.

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

    "?" is a reserved character used to delineate the start of the query string in a URL. If you think you HAVE to use it, convert your embedded ? as %81.

    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 Enthusiast
    Join Date
    Oct 2004
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you! Urlencode is working perfectly in my case!

  10. #10
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Glad you got it working
    Mike
    It's not who I am underneath, but what I do that defines me.


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
  •