Manual talk:$wgActionPaths

From mediawiki.org
Latest comment: 1 year ago by Mexicatribe in topic Using ActionPaths on Nginx

"action" Directory[edit]

I created an "action" directory with an '.htaccess' and an 'index.php'.

# .htaccess
RewriteEngine on
RewriteRule ^(.*?)/(.*?)$ ../index.php?action=$1&title=$2

<?php
# index.php
header('Location: ../');
exit;
?>

From the visitor's side, it's identical. I did this because it would not work in conjunction with my other RewriteRules. Egingell 07:20, 16 August 2007 (UTC)Reply
Didn't work for me Kcmartz 16:33, 10 December 2010 (UTC)Reply

Alternate Option[edit]

On my setup, it would appear that using a '.htaccess' in the wiki root and using:

RewriteRule ^/action/([a-z]*)/(.*)$ /index.php?action=$1&title=$2 [L,QSA]

doesn't work as suggested. Using 'RewriteLog', I found that the following works:

RewriteRule ^action/([a-z]*)/(.*)$ index.php?action=$1&title=$2 [L,QSA]

Hope this helps somebody. Jean-Lou Dupont 01:17, 9 May 2007 (UTC)Reply

Helped me! I had the same problem. You are a legend. Thank you Jldupont! -- 04:56, 12 May 2007 58.10.167.198

Neither works for me, presumably because of my other rewriting. =/ Sy Ali 00:34, 19 May 2007 (UTC)Reply

Infinite Loop[edit]

Using RewriteRule ^/action/([a-z]*)/(.*)$ /index.php?action=$1&title=$2 [L,QSA]

on my .htaccess on (1)(2)(3) and (4) i get an infinite loop :|

RewriteEngine On
(1)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
(2)
RewriteRule ^wiki/(.*) wiki/index.php?title=$1 [PT,L,QSA]
(3)
RewriteRule ^wiki/*$ wiki/ [L,QSA]
RewriteRule ^/*$ wiki/ [L,QSA]
(4)

any ideas? LuisManson

  1. I don't know.
  2. The rule matches everything including 'index.php' (add RewriteRule !^wiki/index.php$ - [C] just before it).
  3. Same story as number 2.
  4. If RewriteRule ^/*$ wiki/ [L,QSA] is number 4, it's still the same problem as numbers 2 and 3.
Egingell 07:20, 16 August 2007 (UTC)Reply

lighttpd and url rewriting[edit]

in your vhost conf or something:

url.rewrite-once = (
		 "^/wiki/$" => "/w/index.php",
     		 "^/wiki/a/([a-z]*)/(.*)$" => "/w/index.php?title=$2&action=$1"
)
url.redirect = ( "^/(?!w|!^wiki/index.php$|wiki|robots\.txt|favicon\.ico)(.*)" => "/wiki/a/$1" )

in LocalSettings.php or wherever:

$wikiRoot = "/wiki";
$wgScript = "{$wgScriptPath}/index.php";
$actions = array('view', 'edit', 'watch', 'unwatch', 'delete',
		 'revert', 'rollback', 'protect',
		 'unprotect','info','markpatrolled','validate',
		 'render','deletetrackback','print',
		 'dublincore','creativecommons','credits',
		 'submit','viewsource','history','purge'
    );
foreach ($actions as $a)
{
    $wgActionPaths[$a] = "{$wikiRoot}/action/$a/$1";
}
$wgArticlePath = "{$wikiRoot}/action/view/$1";


BTW, I don't know if you noticed - I hope you did ;) - that in the lighttpd part, I flipped the rewritten substitutions (I think that's what they're called): "^/wiki/a/([a-z]*)/(.*)$" => "/w/index.php?title=$2&action=$1" -- see the $2 , then $1 ? I did that, otherwise it wouldn't work. I imagine I would have to compensate for older MW installs, that had the action=FOO&title=BAR instead of title=BAR&action=FOO like it is now. Seems to me lighttpd and MW are taking the query string very literally (which is of course a big fat "duh!").

(I didn't use the syntax highlighting, I don't remember the, um, syntax.)

-- Kjikaqawej 08:47, 6 September 2008 (UTC)Reply

...as for apache[edit]

I suppose you could very easily do this for an apache-based mediawiki, since I pretty much ripped the rewrites from that ;).

-- Kjikaqawej 08:49, 6 September 2008 (UTC)Reply

Clean action paths without "action/"[edit]

What are the required LocalSettings and .htaccess configurations to have a setup similar to https://wikitech.wikimedia.org/ ?

ie.

Krinkle 23:13, 12 June 2011 (UTC)Reply

$wgArticlePath = '/view/$1';
$wgActionPaths = array(
  'view' => '/view/$1',
  'edit' => '/edit/$1',
  'history' => '/history/$1',
  'delete' => '/delete/$1',
  'submit' => '/submit/$1',
  'purge' => '/purge/$1'
);
See also wikitech:Project:URL_layout. Ryan lane 23:43, 14 June 2011 (UTC)Reply
Thanks, that looks good. Could you later trace the htaccess/httpd config to enable this as well ? For my localhost I tried the following (mediawiki is installed in htdocs/mediawiki, .htaccess in htdocs/mediawiki/.htaccess) which works, not sure how clean it is though. Krinkle 07:37, 15 June 2011 (UTC)Reply
RewriteEngine On
RewriteRule ^view/(.*)$ index.php?action=view&title=$2 [L,QSA]
RewriteRule ^edit/(.*)$ index.php?action=edit&title=$2 [L,QSA]
RewriteRule ^history/(.*)$ index.php?action=history&title=$2 [L,QSA]
RewriteRule ^delete/(.*)$ index.php?action=delete&title=$2 [L,QSA]
RewriteRule ^submit/(.*)$ index.php?action=submit&title=$2 [L,QSA]
RewriteRule ^purge/(.*)$ index.php?action=purge&title=$2 [L,QSA]

If I understand correctly the wikitech approach would also allow for localistion in LocalSettings.php (e.g. 'view' => '/bearbeite/$1', etc.). Is this true? On wikitech it says that e.g. edit.php is a simple wrapper that sets $_REQUEST['action'] and passes control on to index.php. May you please make available the contens of e.g. edit.php here so that for dummies like me can use it. This would be cool. Cheers and thank you. --[[kgh]] 20:04, 18 October 2011 (UTC)Reply

QSA[edit]

This worked a little better for me....--Hypergrove (talk) 23:57, 24 November 2012 (UTC)Reply

RewriteRule ^/?([a-z]*)/(.*)$ %{DOCUMENT_ROOT}/w/index.php?action=$1&title=$2 [L,QSA]

Using ActionPaths on Nginx[edit]

Hopefully this is the right place for this:


I want to be able to use this on a server running Nginx, is this possible and if so, let's say I want to add the action at the end for example:

example.com/wiki/article/edit

Mexicatribe (talk) 21:27, 6 March 2023 (UTC)Reply