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

examples: Add Examples 5 & 6 and maintainer info request #3601

Merged
merged 6 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# # /examples/
#
# A collection of URL redirection examples.
#
# https://w3id.org/examples/ redirects to
# https://github.com/perma-id/w3id.org/tree/master/examples
#
# ## Contact
# This space is administered by:
#
# Arthit Suriyawongkul
# GitHub username: bact

RewriteEngine on
RewriteRule ^ https://github.com/perma-id/w3id.org/tree/master/examples [R=302,L]
117 changes: 86 additions & 31 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Examples
# /examples/

This permanent W3ID is meant to be a place to host examples for publishing things on w3id.org.

Expand All @@ -9,14 +9,18 @@ This permanent W3ID is meant to be a place to host examples for publishing thing
* [Example 1: Minimalist (grouping)](#example-1-minimalist-grouping)
* [Example 2: Supporting multiple media types (MIME types)](#example-2-supporting-multiple-media-types-mime-types)
* [Example 3: Dealing with query string](#example-3-dealing-with-query-string)
* [Example 4: Publish vocabularies with W3ID](#example-4-publish-vocabularies-with-w3id)
* [Example 5: Version-aware URIs of ontologies](#example-5-version-aware-uris-of-ontologies)
* [Example 6: Redirection based on a file extension in the URL](#example-6-redirection-based-on-a-file-extension-in-the-url)
* [README.md](#readmemd)
* [Publish vocabularies with W3ID](#publish-vocabularies-with-w3id)


## .htaccess

`.htaccess` file is the key for the working of URL redirection service of W3ID. Without it, redirection cannot be done.
`.htaccess` file is the key to the working of URL redirection service of W3ID.
Without it, redirection cannot be done.

### What is `.htaccess?`
### What is `.htaccess`?

From [Wikipedia](https://en.wikipedia.org/wiki/.htaccess):
> An .htaccess (hypertext access) file is a directory-level configuration file
Expand All @@ -25,13 +29,17 @@ issues, such as URL redirection, URL shortening, access control (for different
web pages and files), and more. The 'dot' (period or full stop) before the
file name makes it a hidden file in Unix-based environments.

In W3ID context, it is used primarily for URL redirection. The `.htaccess` file is where you can put URL rewriting rules in. A set of URL rewriting rules will work together and effectively made URL
redirection happen.
In the W3ID context, `.htaccess` is used primarily for URL redirection. This
file is where you can put URL rewriting rules. A set of URL rewriting rules
will work together and effectively make URL redirection happen.

### Put ID info and maintainer info inside .htaccess

You are encouraged to put a breif ID info and a maintainer info in the comment
(lines staring with `#` character) of a `.htaccess` file.
Maintainers of an ID are requested to put brief ID info and maintainer info
in the comments (lines staring with `#` character) of an `.htaccess` file.

Including contact info and GitHub usernames helps ease the overall
maintenance process.

```ApacheConf
# Example
Expand Down Expand Up @@ -87,6 +95,7 @@ You can have more than one *RewriteRule* in a single `.htaccess` file.

See [Apache HTTP Server documentation](https://httpd.apache.org/docs/current/rewrite/intro.html) for more details about *RewriteRule*, regular expressions, and other directives.


### Example 1: Minimalist (grouping)

This 3 lines of code from [/mircat/.htaccess](https://github.com/perma-id/w3id.org/blob/master/mircat/.htaccess) redirects `https://w3id.org/mircat/<ANYTHING>` to `https://fairsharing.github.io/mircat/<ANYTHING>`.
Expand All @@ -107,7 +116,12 @@ When the *Substitution* `https://fairsharing.github.io/mircat/$1` is evaluated,

### Example 2: Supporting multiple media types (MIME types)

A web server can be configured to return different media type or file format depends on the client's request or capability.
A single resource, located by the same URL, can have multiple representations.
For example, an image can can be represented in both GIF and PNG formats.

A web server can be configured to return different media type or file format
depends on the client's request or capability. We call this mechanism a
bact marked this conversation as resolved.
Show resolved Hide resolved
"[content negotiation](https://en.wikipedia.org/wiki/Content_negotiation)".

[/ppop/.htaccess](https://github.com/perma-id/w3id.org/blob/master/ppop/.htaccess) demonstrates the use of `RewriteCond %{HTTP_ACCEPT}` to check which [media types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_Types) the client accepts or expects to be returned by the server.

Expand All @@ -126,11 +140,17 @@ RewriteCond %{HTTP_ACCEPT} text/turtle
RewriteRule ^$ https://protect.oeg.fi.upm.es/ppop/ppop.ttl [R=303,L]
```

The rule set utilizes the *RewriteCond* directive, which "defines a rule condition. One or more RewriteCond can precede a RewriteRule directive. The following rule is then only used if both the current state of the URI matches its pattern, and if these conditions are met" ([Apache HTTP Server documentation](https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond)).
The rule set utilizes the *RewriteCond* directive, which "defines a rule
condition. One or more RewriteCond can precede a RewriteRule directive. The
following rule is then only used if both the current state of the URI matches
its pattern, and if these conditions are met"
([Apache HTTP Server documentation](https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond)).

The above example will have this behavior:
* If `%{HTTP_ACCEPT}` matches `text/html`, the server will return an HTML document (`ppop.html`)
* If `%{HTTP_ACCEPT}` matches `text/turtle`, the server will return a Turtle document (`ppop.ttl`)
* If `%{HTTP_ACCEPT}` matches `text/html`, the server will return an HTML
document (`ppop.html`)
* If `%{HTTP_ACCEPT}` matches `text/turtle`, the server will return a Turtle
document (`ppop.ttl`)

The syntax of `RewriteCond` directive is:
```ApacheConf
Expand All @@ -139,53 +159,88 @@ RewriteCond TestString CondPattern [Flags]

Where *CondPattern* is a regular expresssion to match pattern in *TestString*.

In this case, *TestString* is `%{HTTP_ACCEPT}` which its value is taken from an `Accept` field in the HTTP request header. The `Accept` field can be a string like this:
In this case, *TestString* is `%{HTTP_ACCEPT}` which its value is taken from
bact marked this conversation as resolved.
Show resolved Hide resolved
an `Accept` field in the HTTP request header. The `Accept` field can be a
string like this:

```HTTP
Accept: text/html, application/xhtml+xml, application/xml, image/webp
```

Each media type will be presented, separated by a comma. With that, we can use *CondPattern* to matches media types in this string.
Each media type will be presented, separated by a comma. With that, we can use
*CondPattern* to matches media types in this string.
bact marked this conversation as resolved.
Show resolved Hide resolved


#### Example 3: Dealing with query string
### Example 3: Dealing with query string

Everything after the question mark (`?`) in the URL, but not that `?` itself, is a query string.
Everything after the question mark (`?`) in the URL, but not that `?` itself,
is a query string.

For example, for the URL `https://en.wikipedia.org/w/index.php?title=Web`, the query string is `title=Web`.
For example, for the URL `https://en.wikipedia.org/w/index.php?title=Web`,
the query string is `title=Web`.

As the query string is not included in the string that the *Pattern* of *RewriteRule* will compared against, you cannot use *Pattern* to match them.
As the query string is not included in the string that the *Pattern* of
*RewriteRule* will compared against, you cannot use *Pattern* to match them.

To find pattern in the query string, use `%{QUERY_STRING}` as a *TestString* in *RewriteCond*.
To find pattern in the query string, use `%{QUERY_STRING}` as a *TestString*
bact marked this conversation as resolved.
Show resolved Hide resolved
in *RewriteCond*.

As an example, if you like to redirect the URL `https://w3id.org/examples?a=1&b=2` to `https://example.com/path/file.php?a=1&b=2`, you can use this set of rules:
As an example, if you like to redirect the URL
bact marked this conversation as resolved.
Show resolved Hide resolved
`https://w3id.org/examples?a=1&b=2` to
`https://example.com/path/file.php?a=1&b=2`, you can use this set of rules:

```ApacheConf
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^ https://example.com/path/file.php?%1? [R=302,L]
```

In this example, the *CondPattern* `(.*)` in *RewriteCond* will match every characters in the query string (`a=1&b=2`) and put it in group one. This group one (`%1`) is later used in the *Substitution* of *RewriteRule*.
In this example, the *CondPattern* `(.*)` in *RewriteCond* will match every
character in the query string (`a=1&b=2`) and put it in group one. This group
one (`%1`) is used later in the *Substitution* of *RewriteRule*.

Note that the special character to recall groups from *CondPattern* of
*RewriteCond* is `%` (unlike the special character to recall groups from
*Pattern* of *RewriteRule*, which is `$`).

The character `?` at the end of the *Substitution* of *RewriteRule* tells the
server not to pass the query string to the final URL after rewrite.

Note that the special character to recall groups from *CondPattern* of *RewriteCond* is `%` (unlike the special character to recall groups from *Pattern* of *RewriteRule*, which is `$`).

The character `?` at the end of the *Substitution* of *RewriteRule* tells the server not to pass the query string to the final URL after rewrite.
### Example 4: Publish vocabularies with W3ID

If you plan to publish a vocabulary/ontology with W3ID,
see [`/example/.htaccess`](https://github.com/perma-id/w3id.org/blob/master/example/.htaccess)
and https://w3id.org/example/.

## README.md

Each ID hosted on W3ID is expected to have a file named `README.md` containing an information about the ID itself and an information about the maintainer(s). This can be more elaborate than the information inside `.htaccess`.
### Example 5: Version-aware URIs of ontologies

The `.md` file extension at the end of the file name indicates that the file uses Markdown markup language for text formatting. You can have tables and images as well, if needed.
See [`/OWLunit/.htaccess`](https://github.com/perma-id/w3id.org/blob/master/OWLunit/.htaccess).

GitHub will automatically display the content of a `README.md` to repository visitors.

An example of a good README file: [w3id.org/dggs/README.md](https://github.com/perma-id/w3id.org/blob/master/dggs/README.md)
### Example 6: Redirection based on a file extension in the URL

Check for pattern of a file extension (like `.json`, `.png`, `.rdf`, `.html`)
in the requested URL, and rewrite the URL accordingly.

## Publish vocabularies with W3ID
This technique can compliments `RewriteCond %{HTTP_ACCEPT}` rules (explained
in [Example 2](#example-2-supporting-multiple-media-types-mime-types)).

If you plan to publish a vocabulary/ontology with W3ID,
see https://w3id.org/example/.
See [`/SocDOnt/.htaccess`](https://github.com/perma-id/w3id.org/blob/master/SocDOnt/.htaccess).


## README.md

Each ID hosted on W3ID is required to have a file named `README.md` containing
information about the ID itself and information about the maintainer(s).
This can be more elaborate than the information inside `.htaccess`.

The `.md` file extension at the end of the file name indicates that the file
uses Markdown markup language for text formatting. You can have tables and
images as well, if needed.

GitHub will automatically display the content of a `README.md` to repository
visitors.

An example of a good README file:
[`w3id.org/dggs/README.md`](https://github.com/perma-id/w3id.org/blob/master/dggs/README.md)
4 changes: 3 additions & 1 deletion examples/simple/.htaccess
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Example
# # /examples/simple/
#
# A simple URL redirect example
#
# https://w3id.org/examples/simple/ redirects to https://example.com/
#
Expand Down
6 changes: 3 additions & 3 deletions examples/simple/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## /examples/simple/
# /examples/simple/

An example simple redirection.
A simple URL redirection example.

https://w3id.org/examples/simple/ redirects to https://example.com/
[`https://w3id.org/examples/simple/`](https://w3id.org/examples/simple/) redirects to [`https://example.com/`](https://example.com/).

## Contact
This space is administered by:
Expand Down