Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    95
    Thanks
    8
    Thanked 0 Times in 0 Posts

    How can I escape a ? in a variable

    Hi,

    I have a rewriterule for a news page:-
    Code:
    RewriteRule ^News/([^/]+)/([^/]+) index.php?page=News&feed=$1&name=$2 [L,QSA]
    A url may be something like, I took the %20's out for readablity
    www.mydomain.com/News/Latest News/Is This Right? Find Out Here

    The $_GET['name'] variable only includes up to the ?, how can I get it to include the part after it too?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You'll need to do a querystring evaluation, since querystrings are not matched by pattern for rewrite rule.
    The question mark doesn't belong in the url. It separates the url from the querystring, and apache knows this as well. These characters should be encoded instead, otherwise you'll need to stack your rewritecond to handle the querystrings.
    As for your GET, you can try under $_GET['Find Out Here'], which will contain no value.

  • #3
    New Coder
    Join Date
    Mar 2004
    Posts
    95
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    You'll need to do a querystring evaluation, since querystrings are not matched by pattern for rewrite rule.
    The question mark doesn't belong in the url. It separates the url from the querystring, and apache knows this as well. These characters should be encoded instead, otherwise you'll need to stack your rewritecond to handle the querystrings.
    As for your GET, you can try under $_GET['Find Out Here'], which will contain no value.
    Thanks for the suggestions. I am a bit lost with this as I am not experienced with this sort of stuff. Most of the information I can find on querystring evaluation is used to convert something like
    http://mydomain.site/page.php?id=1
    to
    http://mydomain.site/page/1

    I need to do the reverse
    http://mydomain.site/page/this?-has-a-question
    into
    http://mydomain.site/index.php?page=page&name=this?-has-a-question

    So I need a way to grab the querystring from the url
    http://mydomain.site/News/Latest News/this?-has-a-question
    which would be "-has-a-question"
    and then append that to my rewrite rule
    RewriteRule ^News/([^/]+)/([^/]+) index.php?page=News&feed=$1&name=$2&extra=%1 <-- append the "-has-a-question" here as another variable.

    I have been trying all sorts of things for the last hour, but I have no idea what I am doing. If someone can help with this I would really appreciate it.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Yeah, what I'm saying though is this won't match a pattern for a rewrite rule: http://mydomain.site/page/this?-has-a-question. As soon as you have applied the ? in there, it now sees it as a querystring and not as a part of the immediate url, so while you can match it, you can only match up to the /this. You should encode the characters instead so the ? is passed through in its encoded form instead of as a ?.

    Simply using QSA will append the querystring. As you have done here, evaluate the $_GET with a print_r($_GET) and it should show that the "Find Out Here" is an offset. Since it contains no value though, all you can do is evaluate the isset check. You can't apply it as an extra in this sense as the QSA's purpose is to simply apply the querystring after the rewrite and pass it through.

    You can use rewritecond to evaluate a querystring though. Encode the data that you have passed it; I'm not sure how it would turn out attempting to take a part from the rewrite rule and a part from the rewrite cond. I don't use rewrite cond enough to be sure, but I think its doable though I would think it would be messy for something that shouldn't be. On the otherhand, a simple urlencode() before writing the parts will let it be attached directly from the rewrite rule.

  • #5
    New Coder
    Join Date
    Mar 2004
    Posts
    95
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Yeah, what I'm saying though is this won't match a pattern for a rewrite rule: http://mydomain.site/page/this?-has-a-question. As soon as you have applied the ? in there, it now sees it as a querystring and not as a part of the immediate url, so while you can match it, you can only match up to the /this. You should encode the characters instead so the ? is passed through in its encoded form instead of as a ?.

    Simply using QSA will append the querystring. As you have done here, evaluate the $_GET with a print_r($_GET) and it should show that the "Find Out Here" is an offset. Since it contains no value though, all you can do is evaluate the isset check. You can't apply it as an extra in this sense as the QSA's purpose is to simply apply the querystring after the rewrite and pass it through.

    You can use rewritecond to evaluate a querystring though. Encode the data that you have passed it; I'm not sure how it would turn out attempting to take a part from the rewrite rule and a part from the rewrite cond. I don't use rewrite cond enough to be sure, but I think its doable though I would think it would be messy for something that shouldn't be. On the otherhand, a simple urlencode() before writing the parts will let it be attached directly from the rewrite rule.
    Thanks for your help Fou-Lu. I was hoping to not have to use urlencode() as it sort of defeats the purpose of using the title in the url, but at least it solves the problem and allows special characters. Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •