Mailing List Archive

Losing the index.php
Howdy,

I've been experimenting with RewriteRules and LocalSettings.php
to get rid of the "index.php" in the URL, but I'm running into
unexpected problems.

The setup now seems to work using:

---- LocalSettings.php ----------------------------------
$wgScriptPath = "";
$wgScript = $wgScriptPath . "/index.php";
---------------------------------------------------------

"Seems", because there is a strange balance between Apache and
PHP keeping the "index.php" most of the time out of the URL. The
correct setup would be:

---- LocalSettings.php ----------------------------------
$wgScriptPath = "";
$wgScript = "";
---------------------------------------------------------

but this causes an infinite "Error 302 Moved Temporarily" loop
(Using Firefox, Apache 2.0.52, Squid 2.5 and Mediawiki 1.3.8) for
the URL in the script tag on each page:

<script src="?title=-&amp;action=raw&amp;gen=js&amp;smaxage=0"
type="text/javascript"></script>

It looks like the empty $wgScript causes the mayhem in the
function getLocalURL() in Title.php (via Skin.php and SkinPHPTal.php).
The code looks sensible, though.

My RewriteRules look like this:

---- httpd.conf -----------------------------------------
RewriteEngine On

# Redirect old /wiki/ urls
RewriteRule ^/wiki/(.*)$ http://www.rapdict.org/$1 [R,L]

RewriteRule ^/index.php/(.*)$ http://www.rapdict.org/$1 [R,L]

# Don't rewrite requests for files in MediaWiki subdirectories,
# MediaWiki PHP files, HTTP error documents, favicon.ico, or robots.txt
RewriteCond %{REQUEST_URI} !^/(stylesheets|images|skins)/
RewriteCond %{REQUEST_URI} !^/(redirect|texvc|index).php
RewriteCond %{REQUEST_URI} !^/error/(40(1|3|4)|500).html
RewriteCond %{REQUEST_URI} !^/favicon.ico
RewriteCond %{REQUEST_URI} !^/robots.txt

# Rewrite http://wiki.domain.tld/article properly, this is the main rule
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
---------------------------------------------------------

Does anyone know how to counter the infinite 302 loop for that script
URL?

Greetings,

Patrick

--
_______________________________________________________________
Patrick Atoon ___________________ mailto:patricka@rapdict.org
_____________________________________ http://www.rapdict.org/
Re: Losing the index.php [ In reply to ]
On Nov 30, 2004, at 3:10 PM, Patrick Atoon wrote:
> ---- LocalSettings.php ----------------------------------
> $wgScriptPath = "";
> $wgScript = $wgScriptPath . "/index.php";
> ---------------------------------------------------------
>
> "Seems", because there is a strange balance between Apache and
> PHP keeping the "index.php" most of the time out of the URL. The
> correct setup would be:

What have you set $wgArticlePath to? This is what is used for plain
view URLs, and should be the focus of your efforts.

> ---- LocalSettings.php ----------------------------------
> $wgScriptPath = "";
> $wgScript = "";

Don't ever do that, as you won't get correct URLs. $wgScript must be an
absolute path, starting with a slash, and needs to consistently
resolve.

> # Rewrite http://wiki.domain.tld/article properly, this is the main
> rule
> RewriteRule ^(.*)$ /index.php/$1 [L,QSA]

This will fail for page titles containing "?"

To get full coverage, use the rewrite patch for Apache 1.3.x (in the
maintenance subdirectory) which converts ampersands, and send those as
a query string instead of path_info.

-- brion vibber (brion @ pobox.com)
Re: Losing the index.php [ In reply to ]
Brion Vibber wrote:

> I wrote:
>
> > # Rewrite http://wiki.domain.tld/article properly, this is the main
rule
> > RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
>
> This will fail for page titles containing "?"
>
> To get full coverage, use the rewrite patch for Apache 1.3.x (in the
maintenance subdirectory) which converts ampersands, and send those as a
query string instead of path_info.


Hmmmm, I don't feel comfortable patching my stock Apache 2.0.52 as
it makes future upgrades more complex. I guess that means only
partial loss of the index.php, except for cases where "index.php?"
is used.

My current setup:

------- LocalSettings.php -----------------------------------
$wgScriptPath = "";
$wgScript = $wgScriptPath . "/index.php";
$wgRedirectScript = $wgScriptPath . "/redirect.php";

## If using PHP as a CGI module, use the ugly URLs
$wgArticlePath = "${wgScript}/$1";
-------------------------------------------------------------


------- httpd.conf ------------------------------------------
RewriteEngine On

# Redirect old /wiki/ URLs
RewriteRule ^/wiki/(.*)$ http://www.rapdict.org/$1 [R,L]

# Redirect "/index.php/" URLs
RewriteRule ^/index.php/(.*)$ http://www.rapdict.org/$1 [R,L]

# Don't rewrite "/index.php?" URLs
RewriteCond %{REQUEST_URI} !^/index.php\?

# Don't rewrite requests for files in MediaWiki subdirectories,
# MediaWiki PHP files, HTTP error documents, favicon.ico, or robots.txt
RewriteCond %{REQUEST_URI} !^/(stylesheets|images|skins)/
RewriteCond %{REQUEST_URI} !^/(redirect|texvc|index).php
RewriteCond %{REQUEST_URI} !^/error/(40(1|3|4)|500).html
RewriteCond %{REQUEST_URI} !^/favicon.ico
RewriteCond %{REQUEST_URI} !^/robots.txt

# Rewrite "/Article" to "/index.php/Article" for internal use
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
-------------------------------------------------------------

To avoid the double requests (logically) appearing in the Apache
logfile, I have patched the function getLocalURL() in Title.php
by adding one line at line 418, just before "return $url":

------ Title.php --------------------------------------------
$url = str_replace( "/index.php/", "", $url);
-------------------------------------------------------------

That seems to do the trick for pretty much all links.

> -- brion vibber (brion @ pobox.com)


Thanks for the help!

Greetings,

Patrick

--
_______________________________________________________________
Patrick Atoon _____________________ mailto:patricka@two4u.com
_______________________________________ http://www.two4u.com/


--
_______________________________________________________________
Patrick Atoon ___________________ mailto:patricka@rapdict.org
_____________________________________ http://www.rapdict.org/
Re: Losing the index.php [ In reply to ]
> My current setup:
>
> ------- LocalSettings.php -----------------------------------
> $wgScriptPath = "";
> $wgScript = $wgScriptPath . "/index.php";
> $wgRedirectScript = $wgScriptPath . "/redirect.php";
>
> ## If using PHP as a CGI module, use the ugly URLs
> $wgArticlePath = "${wgScript}/$1";
> -------------------------------------------------------------

Now
$wgArticlePath = "${wgScript}/$1";

Should be
$wgArticlePath = "/$1";

Regards,
Plamen
Re: Losing the index.php [ In reply to ]
Plamen Gradinarov wrote:

> Now
> $wgArticlePath = "${wgScript}/$1";
>
> Should be
> $wgArticlePath = "/$1";

Hahaha! I can't believe I missed that one! Thanks for the correction;
no need to patch Title.php now.

> Regards,
> Plamen

Greetings,

Patrick

--
_______________________________________________________________
Patrick Atoon ___________________ mailto:patricka@rapdict.org
_____________________________________ http://www.rapdict.org/