Experimental project

This is a sandbox project, which contains experimental code for developer use only.

This module provides the ability to rewrite URL query parameters into Clean URL components on specified paths.

Motivation

Views exposed filters generates URLs with multiple query parameters, and the URL path gets unwieldy fast if there are multiple filters and filter values used. Furthermore because the path contains query parameters, it might impact SEO results.

An example of a dirty URL like that could be:
example.com/events?field_category_id[0]=100&field_category_id[1]=101&field_author_name[0]=John

Using this module you can transform the URL into:
example.com/events/p/field_category_id/0__100--1__101/field_author_name/John

Or an even shorter URL if you use the provided alter hooks:
example.com/events/p/cat_id/0__100--1__101/name/John

Isn't that a joy to look at?

Configuration

The following configuration options are present:

  • Allow disabling all path rewriting by un-checking checkbox.
  • Allow configuring which characters should be used for delimiting query parameters. Care should be taken, to only use characters that are valid in an URI path component, as well as making sure the characters don't normally appear in the URL, so that the decoding process is correct (refer to RFC 3986 https://tools.ietf.org/html/rfc3986#section-3.3 for allowed characters details).
  • Allow setting a regular expression which is used to determine on which paths query parameter rewriting should occur.
  • Additional rewrite-enabled paths can be added by implementing hook_query_parameters_to_url_rewrite_access().
  • Allow rewriting the final encoded URLs by implementing **hook_query_parameters_to_url_rewrite_alter()**.
  • This allows you renaming the query parameter keys and values to be shorter or more SEO friendly.
    See query_parameters_to_url.api.php for documentation and an example.
  • Experimental feature to allow saving menu items with rewritten URLs that contain encoded query parameters.
  • Enable caching of the rewritten URL pages by applying a patch to core.

Usage

Enable the module, go to the configuration form, configure on which paths should rewriting occur, using a regular expression.

Example regular expressions:

  • "{}" or "{.+}" - Enable query parameter rewriting on all Drupal paths.
  • "" (empty) - Disable query parameter rewriting on all Drupal paths.
  • "{^events|^news}" - Enable query parameter rewriting on all paths that start with events or news.
  • "{^node/([0-9]+)/(.+)}" - Enable query parameter rewriting on all node paths (view, edit, etc).

A more in-depth README is available alongside the module.

Supporting organizations: 
Mentors solved queries related to this module

Project Information