Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP Accept header for ontology URLs with and without version #1099

Closed
aljoshakoecher opened this issue Jan 25, 2023 · 1 comment
Closed

Comments

@aljoshakoecher
Copy link

Hey everyone,
I am setting up a W3ID redirect and I want to ensure content negotiation, i.e.

  • if a user enters the ontology IRI in a browser, he should be redirected to an HTML page
  • if a user imports the ontology using a tool such as Protege, the ontology should be served

Furthermore, I want to have proper versioning for the ontology so that a specific version may be imported. For all this, I have created the following .htaccess file:

# Redirect ontology with version
RewriteCond %{HTTP_ACCEPT} application/rdf\+xml [OR]
RewriteCond %{HTTP_ACCEPT} text/turtle
RewriteRule ^css/(\d\.\d\.\d)/?$ https://raw.githubusercontent.com/<repo>/v$1/<file> [R=301,NC]

# Redirect for ontology without version left out..
RewriteCond %{HTTP_ACCEPT} application/rdf\+xml [OR]
RewriteCond %{HTTP_ACCEPT} text/turtle
RewriteRule ^css/?$ https://raw.githubusercontent.com/<repo>/main/<file> [R=301,NC]

# Redirect HTML requests to the main repository page
RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml)
RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteRule ^css/?$ https://github.com/<repo> [R=301,NC]

What this does is basically:
Check the HTTP Accept header. If it is set to application/rdf+xml or text/turtle then serve the ontology file. If the URL contains a version, use that version to get the exact ontology version. If there is no version, return the current file of the main branch.
If the HTTP Accept asks for HTML, just redirect to the repository page.

Now to the problem:

  • HTML works fine
  • The redirect for the non versioned URL, i.e. http://www.w3id.org/.../css works fine, too
  • The redirect for the versioned URL, i.e. http://www.w3id.org/.../css/1.0.0 does not work. Apparently, Protege doesn't set a proper HTTP Accept for this URL because the RewriteConds are not fulfilled. If I remove the RewriteConds or add one for the wildcard HTTP Accept */*, the redirect for a URL with version works, too.

Why does Protege set different HTTP Accept headers for these two URLs?

  1. http://www.w3id.org/.../css
  2. http://www.w3id.org/.../css/1.0.0

Is this intentional?

@aljoshakoecher
Copy link
Author

aljoshakoecher commented Jan 25, 2023

After some wasted hours I just stumbled across an issue in the W3id repo that helped me resolve this issue:
perma-id/w3id.org#2021

Solution: Protege seems to expect a 303 status code. Imports worked for me as soon as I changed from 301 to 303 for the ontology redirects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant