Forum Moderators: phranque

Message Too Old, No Replies

Redirect query_string with "&amp" to ";"

Since ";" is the recommended delimiter

         

lierduh

12:25 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



I am trying to have a redirect to have

/news.php?cat=1&pg=4
redirect to
/news.php?cat=1;pg=4

I have used

RewriteCond %{query_string} ^cat\=([0-9]+)\&pg\=([0-9]+)
RewriteRule ^news\.php$ /news.php?cat=%1;pg=%2 [R=301,L]

The log shows:

"GET /news.php?cat=1&pg=4 HTTP/1.1" 301 254 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows

"GET /news.php?cat=1%3bpg=4 ...

So looks like the ";" has not been treated as a delimiter. The rewrite urlencoded it as '%3b'.

How can I force ";" to be the delimiter?

lierduh

2:03 am on Jul 28, 2005 (gmt 0)

10+ Year Member



Looks like Google treats two URLs using two different delimiters as the same page. So there is no need to redirect in the fear of duplicate contents penalty.

jdMorgan

2:13 am on Jul 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is the source of the recommendation to use ";" as a query parameter delimiter? I've heard this issue mentioned once before, but I have always considered "&" to be the safe choice for compatibility with Apache mod_rewrite's [QSA] (Query String Append) flag.

Jim

Wizcrafts

4:09 am on Jul 29, 2005 (gmt 0)

10+ Year Member



JD asked:

What is the source of the recommendation to use ";" as a query parameter delimiter?

The ; isn't the entire problem, it is the entire expression, &, which is the W3C approved method of using the ampersand character in html codes. To pass validation your (X)html markup must not contain unadorned ampersands, but must have them converted to &. When converted ampersands are included in URL's they are understood and translated into ANDs by the server scripts that process them. Unfortunately, as the OP discovered, this causes problems when you are incorporating such converted codes into a .htaccess directive. It is safer to just use the & character in URLs that may be processed in .htaccess, but your code will not validate at the W3C HTML Validator website.

Wiz

lierduh

8:22 am on Jul 29, 2005 (gmt 0)

10+ Year Member



What is the source of the recommendation to use ";" as a query parameter delimiter?

It is recommended by W3C. I have found this link:

[w3.org...]

There may be more information exists other than this.

jdMorgan

2:43 pm on Jul 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



From the cited W3C link:
We recommend that HTTP server implementors, and in particular, CGI implementors support the use of ";" in place of "&" to save authors the trouble of escaping "&" characters in this manner.

Ah, OK. In this case, I'd say that the best thing to do at this time is to ignore the character-entity validation problem until such time as the major servers handle it gracefully.

It's one of those, "If you want to make an omelet, you have to break some eggs"-type problems. W3C is "out-front" on this issue, and the server implementors will have to catch up.

Jim