& and mod rewrite

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
   I'm thinking I'm not the only one that has this problem.

   Les say you have a URL that you want to rewrite to be search engine


RewriteRule ^(.*[a-z]+)-\/([^/]+)\/([^/]+)$  $1.php?$2=$3 [NE]

with a rule like that the SEO link would be:


But that always translates to this after the %26 is reinterpreted:


   Now, if it was just me, I'd never use ampersands, but I find it
impossible to keep clients from using them.

   So, assuming I don't to find another line of business, what is the

   I'm considering swapping "&" for "^", and then swapping back. I've
never seen a carot in a product or category name. Obviously, that's a


Re: & and mod rewrite

jeff wrote:

Quoted text here. Click to load it

The ampersand is just the default delimiter for arguments to a script,
and the script can use whatever delimiter you choose in place of it.
I'm confused why you'd swap it and then swap it back creating double
the processing.  Search engine friendly URL's shouldn't contain a ? or
&, and just replace it, usually with a more common delimiter such as
|, , or /, where the script doesn't know the difference.

Re: & and mod rewrite

jeff wrote:
Quoted text here. Click to load it

If I am understanding you correctly, you want to use "%26" (the ASCII
code for an ampersand) instead of an actual ampersand in the rewritten
URL. It sounds to me like you are trying to solve the same problem
twice. One of the purposes of using mod_rewrite with your URL is to
eliminate having ampersands & question marks (the typical delimiters) in
your URL. The idea is to have a URL that is comprehensible, both to
people and to Googlebot. Having real words in the URL, which correspond
to real words in your page, is good for SEO. It also makes it a lot
easier for real people to remember URLs in your site.

In general, the ampersand is talking to the web script, as a delimiter.
It sounds like you also want to use it as a "meaningful" thing, talking
to the human visitor.

Instead of <http://yoursite.com/category/b&w/ or
<http://yoursite.com/category/b%26w/ (or, for that matter,
<http://yoursite.com/category/b&amp ;w/>), why not have something like:

   * http://yoursite.com/category/b-w /
   * http://yoursite.com/category/b-and-w /

It seems to me that once you've got your mod_rewritten, nice, clean,
SEO-friendly URL, ampersands (of any variety) shouldn't really appear in
them. Unless, of course, an ampersand is what you really, really want to
be saying as part of the URL. In that case, "&amp;" is the proper way to
express that.


Re: & and mod rewrite

David Hennessy wrote:
Quoted text here. Click to load it


Quoted text here. Click to load it

   Hmm, the second might work. The first won't because the "-" is
commonly used, so it would be impossibly to tell an "&" from a "-",
remember that a script has to take the client entered data and convert
the "&". Words with "and" in them are common, but not -and-, so that
seems good.

   Thanks, I'll give it a go. Although I wonder if I shouldn't just
spell out ampersand, nobody writes that!

Quoted text here. Click to load it

Site Timeline