Topic on Manual talk:Short URL/Apache

Added {{Outdated}} Template to flag major cleanup

7
DanShearer (talkcontribs)

Every few years I come to this page to implement short URLs, then remember it is horribly confusing and work it out again from scratch. As many people have pointed out, the content seems authoritative but is unlikely to work on any Apache installation. In addition to being incorrect, it is also confusing. So let's start.

One of the first things is to split up Alias from Rewrite techniques into separate sections. Pretty sure the commenter here is correct in saying that Apache recommend Alias over Rewrite although I don't know a reference for that. So the Alias version should probably be listed first.

There are some working or almost-working recipes on this talk page to give us a start.

DanShearer (talk) 22:14, 18 November 2021 (UTC)

2003:DE:F743:E8FF:149C:39B2:C753:C9C9 (talkcontribs)

So it was wrong in multiple ways to blame myself for failing on this short URL task. Thank you @DanShearer for posting here and thanks even more for picking up the adventure to rewrite the page from scratch. --Paddy F. from G.

DanShearer (talkcontribs)

Thanks Paddy. I could probably make a bigger difference in a few minutes, except I don't know how to edit with the translation tags. Is there a tool that makes that easy?

Ciencia Al Poder (talkcontribs)

You can edit without adding any translation tags, and someone with knowledge will add them when you're done

DanShearer (talkcontribs)

I hardly know where to start, but I've done a bit of poking around. If someone wants to do a lot of deleting that would be good.

Dantman (talkcontribs)

Alias version should not be listed first, it shouldn't even be here at all. Alias should not be used. I've never seen the reference for Apache recommending Alias over RewriteEngine. But I have a feeling that if it exists at all it's a generic recommendation that is being mis-applied to MediaWiki.

The way Alias works is fundamentally wrong and only works because MediaWiki ignores the bad side effects that Alias introduces.

Proper rewrite rules just rewrite the path to /index.php, without any suffix or query modifications. Basically they just tell Apache, "For this url, run index.php without modifying anything". MediaWiki, not Apache, then reads the whole /wiki/Page path from the raw url in $_SERVER['REQUEST_URI'] and MediaWiki parses out the "Page" page name.

That is not how Alias works. A Alias /wiki /index.php alias actually tells apache to rewrite /wiki/Page to /index.php/Page and then passes "Page" to $_SERVER['PATH_INFO'] expecting you'll use PATH_INFO to get the "Page" title.

However, this is not actually a useful or good thing. Read the MediaWiki source code.

"PATH_INFO is mangled due to https://bugs.php.net/bug.php?id=31892" "And also by Apache 2.x, double slashes are converted to single slashes."

If MediaWiki actually used the PATH_INFO that you get by using an Alias instead of a RewriteRule, your wiki's urls could be broken.

The only reason that Alias rewrites work, is because MediaWiki outright ignores the PATH_INFO and takes responsibility for parsing the "Page" title out of the url in REQUEST_URI. i.e. It basically throws the extra stuff Alias does into the trash and demotes it to a basic RewriteEngine rewrite.

DanShearer (talkcontribs)

Dantman - ack on the reasons for deprecating Alias, which themselves need to be mentioned when deprecating it and removing recipes.

Reply to "Added {{Outdated}} Template to flag major cleanup"