How do I prevent delimiters in a URL from being URL encoded?

I need to know how to get a +-delimited string to be appended to the end of the URL path without the + character being URL encoded.

Why: I’m trying to pass arguments to a View. I’m working on a custom module to conditionally route webform confirmations to a View. The view will take multiple arguments, returning all nodes matching the arguments (currently trying to do this with Views 3.0).

I’ve done proof-of-concept tests on the view that demonstrate that for a view with a path of, say, cbos/name1+name2 it will produce the desired result (i.e., displays nodes name1 and name2). So I know that this can be done from the Views side. (I’m pretty certain at this point Views has nothing to do with it, I just need to make clear why I need to do this.)

The problem is on the custom module / webform side.

I’m creating the URL path using the following code:

while ($cbo_short_name = db_fetch_array($result)) { if ($count > 0) $delim = '+'; $cbo_short_names_arg .= $delim.$cbo_short_name['cbo_short_name']; $count = $count + 1; } $redirecturl = "cbos/".$cbo_short_names_arg; $node->webform['confirmation'] = drupal_urlencode($redirecturl); // ... have also tried setting this via the form settings page using tokens 

… where $cbo_short_name is an array of short names (usually initials) for organizations. (There’s usually only 1, but in about 15% of cases there will be 2 or 3 short names. The visitor has to be shown all of them. Hence, the View)

What this should do is produce a URL path of the form given above; what’s happening is that ‘+’ is getting URL encoded as %2B (e.g. cbos/name1%2Bname2), which breaks the Views argument string — only the first result is returned.

If I could somehow force ‘+’ to be passed intact, without URL encoding, this would work. But I’m at a loss for how to do that.

What I’ve tried so far:

  • Setting the confirmation URL on the form settings page (preferred, since I don’t have to hard code it).
  • Setting the redirect URL programmatically (what you see above).

Both work to set a value, but in both cases the delimiters are URL encoded in the resulting URL path.

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

How do I prevent delimiters in a URL from being URL encoded?

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.