rules.csv format
Draft
Any folder can contain a rules.csv
files. The .htaccess
in the same folder will be generated/modified, if:
- There is no
.htaccess
already - or the
.htaccess
contains a## DO NOT EDIT
comment
Thus the rules.csv
files will generate rules for URLs under that folder, e.g. the file example/rules.csv
defines how to handle anything under https://w3id.org/example/
.
rules.csv
is a contains a series of URL patterns, using "
as quote symbol, ,
as separator and #
as comment.
The first row MUST be the header row, starting with at least:
"src","dest","statuscode","mediatype"
- The
src
column contains the path that should be matched, relative to the current directory.- The path MUST NOT start with
/
or./
- The string
.
can be used to match the folder root (e.g./example/
) - The empty string (
""
in the CSV) can be used to match the folder root without a trailing/
(e.g./example
)- If `` is listed, without listing
.
, then the folder root
- If `` is listed, without listing
- If the path starts with
^
and ends with$
, then it is interpreted as a Regular Expression. Groups specified using(.*)
and similar can be used as$1
etc. in thedest
column.
- The path MUST NOT start with
- The
dest
column contains the absolute URI to redirect to. If thepath
is specified as a regular expression, groups can be referenced by their positions, e.g.$1
for the first group. - The column
"statuscode"
is optional (per row or per file), the default is"302"
(Found). It SHOULD be one of the 3xx redirection codes. - The column
"mediatype"
is optional (per row or per file), the default is""
(no content negotitation)
The required and optional columns MUST be in the above order. For consistency, if the optional mediatype
column is present, then the optional statuscode
column MUST also be present. All columns must be declared in the header row.
Example (/example/rules.csv
) contains:
"src","dest","statuscode","mediatype"
".","http://example.com/home","301",""
"me","http://example.com/about-me.html","303","text/html"
"me","http://example.com/about-me.jsonld","303","application/ld+json"
"me","http://example.com/about-me.html","303",""
"sub/folders/allowed","http://example.com/flat.html","",""
"^blog/(.*)/","http://example.com/blog/post/$1/","307",""
As a table:
src | dest | statuscode | mediatype |
---|---|---|---|
. | http://example.com/home | 301 | |
me | http://example.com/about-me.html | 303 | text/html |
me | http://example.com/about-me.jsonld | 303 | application/ld+json |
me | http://example.com/about-me.html | 303 | |
sub/folders/allowed | http://example.com/flat.html | ||
^blog/(.*)$ | http://example.com/blog/post/$1/ | 307 |
The first entry redirects https://w3id.org/example/ to http://example.com/home using a HTTP status 301 Moved Permamently
Second row redirects https://w3id.org/example/me to http://example.com/about-me.html, this time using HTTP status 303 See Other
, if the client requests Accept: text/html
.
Third row redirects https://w3id.org/example/me to http://example.com/about-me.jsonld, this time using HTTP status 303 See Other
, if the client requests Accept: application/ld+json
.
Fourth row redirects https://w3id.org/example/me to http://example.com/about-me.html, this time using HTTP status 303 See Other
, if the client didn't match the previous content types. (Otherwise the server would say 404 Not Found
).
Fifth row redirects https://w3id.org/example/sub/folders/allowed to http://example.com/flat.html using the default HTTP status 302 Found
.
The sixth row is a regular expression, so any hits like https://w3id.org/example/blog/hello-world would redirect to http://example.com/blog/post/hello-world/ - here with a 307 Temporary Redirect