Skip to content

Commit

Permalink
Rewrite ? as %3F
Browse files Browse the repository at this point in the history
As this is now a static site, the URLs point to files with those names, e.g. `http://spaconference.org/mediawiki/index.php?title=SpaTwoThousandAndFifteenOutput`, i.e. the filenames actually contain a `?`. However, the `?` reserved meaning in the browser, to indicate a query string. So it will not be looking for a file that is called index.php?something.

This change rewrites the `?`s to `%3F`s, so the browser can find the files.

So I can remember what this means next time, let's spell this out.

`RewriteCond` is the condition under which the following rewrite rule will be applied. "The first argument is a variable describing a characteristic of the request, the second argument is a regular expression that must match the variable" (https://httpd.apache.org/docs/trunk/rewrite/intro.html). So what we are saying here is: "when there is a query string consisting of one or more characters".

`RewriteRule` is what we should do in that case. The rewrite rule is made up of three parts: a pattern, a subsitution, and optional flags.

In this case, the pattern is where the path (i.e. up to the query string) is `index.php`, and the substitution is $1 (i.e. `index.php`), plus `%3F` (escaped as % has meaning), plus `%1` which is the match for the `RewriteCond` (i.e. the former query string).

The [L] flag means last – stop here and don't evaluate any other rules if you've done this one.
  • Loading branch information
annashipman committed Jul 12, 2017
1 parent 8faf8c9 commit 93ccd2b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mediawiki/.htaccess
@@ -1,3 +1,7 @@
<FilesMatch "\.php\?">
Header set Content-Type "text/html"
</FilesMatch>

RewriteEngine on
RewriteCond %{QUERY_STRING} (.+)
RewriteRule ^(index\.php)$ $1\%3F%1 [L]

0 comments on commit 93ccd2b

Please sign in to comment.