Trying to change a URL to have ampersands & is usually straight forward, you use %26.

However , throw in apahe mod_rewrite and PHP and things get a bit more complicated. Using the example – Books Forms & Pads – its URL encoded as:


Apache will rewrite the url and PHP will pick up the ampersand as another variable. So assuming the variable was originally id it becomes:

array(2) { [“id”]=> string(12) “books-forms-” [“-pads”]=> string(0) “” }   Note the -pads as a blank variable.

Using the B flag in the rewrite , this get apache to escape and voila – PHP gets it all as a single variable.

array(1) { [“id”]=> string(18) “books-forms-&-pads” }

Adam Skinner

Web developer who takes a keen interest in FOSS and other technical subjects. Currently learning laravel