4

I have an Open Search XML for a web app that looks something like this:

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
    <ShortName>AppName</ShortName>
    <Description>Search App</Description>
    <InputEncoding>UTF-8</InputEncoding>
    <Image width="32" height="32" type="image/png">https://not.my.app.url/public/favicon.png</Image>
    <Url type="text/html" method="get" template="https://not.my.app.url/$/search?q={searchTerms}"/>
</OpenSearchDescription>

A problem with this is that if I want to host the app on a different URL than https://not.my.app.url I would have to either manually edit the manifest to match the new hostname or use some sort of preprocessor that puts the right hostname there. Is there any way I can have a relative path instead? I tried simply omitting the hostname and protocol specifier, but then Firefox refused to install it as a search provider (I did not test any other browsers).

Newbyte
  • 2,421
  • 5
  • 22
  • 45

1 Answers1

2

The OpenSearch specification defines the URL template grammar as:

ttemplate      = tscheme ":" thier-part [ "?" tquery ] [ "#" fragment ]
tscheme        = *( scheme / tparameter )
thier-part     = "//" tauthority ( tpath-abempty / tpath-absolute / tpath-rootless / path-empty )
tauthority     = [ tuserinfo "@" ] thost [ ":" tport ]
tuserinfo      = *( userinfo / tparameter )
thost          = *( host / tparameter )
tport          = *( port / tparameter )
tpath-abempty  = *( "/" tsegment )
tsegment       = *( segment / tparameter )
tpath-absolute = "/" [ tsegment-nz *( "/" tsegment ) ]
tsegment-nz    = *( segment-nz / tparameter )
tpath-rootless = tsegment-nz *( "/" tsegment )
tparameter     = "{" tqname [ tmodifier ] "}"
tqname         = [ tprefix ":" ] tlname
tprefix        = *pchar
tlname         = *pchar
tmodifier      = "?"
tquery         = *( query / tparameter )
tfragement     = *( fragement / tparameter )

As you can see the scheme and the hosts are required.

In other words, relative URLs are not allowed.
You must use an absolute URL, like http://example.com/search?q={searchTerms}.

Benoit Blanchon
  • 13,364
  • 4
  • 73
  • 81