Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-05-2012, 02:11 AM   PM User | #1
Taipan
New Coder

 
Join Date: Mar 2004
Posts: 95
Thanks: 8
Thanked 0 Times in 0 Posts
Taipan is an unknown quantity at this point
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?
Taipan is offline   Reply With Quote
Old 06-05-2012, 03:38 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,648
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 06-06-2012, 12:40 AM   PM User | #3
Taipan
New Coder

 
Join Date: Mar 2004
Posts: 95
Thanks: 8
Thanked 0 Times in 0 Posts
Taipan is an unknown quantity at this point
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.
Taipan is offline   Reply With Quote
Old 06-06-2012, 05:29 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,648
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 06-06-2012, 10:15 PM   PM User | #5
Taipan
New Coder

 
Join Date: Mar 2004
Posts: 95
Thanks: 8
Thanked 0 Times in 0 Posts
Taipan is an unknown quantity at this point
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.
Taipan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:20 PM.


Advertisement
Log in to turn off these ads.