views:

495

answers:

5

Hi,

I have a personal website with a MediaWiki installation on a shared host. The Apache configuration treats all .php request with PHP 4, and all .php5 requests with PHP5.

For compatibility reasons I need to be able to use the .php extension, but MediaWiki is only available on PHP5. I tried to use the mod_rewrite engine, but I'm stuck with the rule.

Here's the current file:

DirectoryIndex index.php5

RewriteEngine on


# This rewrites URIs in the form /pages/Article_Name to /index.php5?title=Article_Name.
RewriteCond %{REQUEST_URI} !^/pages/index.php5.*$ [NC]
    RewriteRule ^pages/?(.*)$ /index.php5?title=$1 [L]

# This is the broken rule
RewriteCond %{REQUEST_URI} ^index\.php(([^5])(.*))?$ [NC]   
    RewriteRule ^index\.php(([^5])(.*))?$ /index.php5?$1 [L]

The idea of the rule was "Redirect all content from index.php (not followed by '5') to index.php5".

Any idea?


Edit:

SetEnv PHP_VER 5

works, but I'm still interested on why the rule was not taken into account.

A: 

Try this

AddType x-mapp-php .php5

It might be the other way around, try it though, i cant atm :S

Ólafur Waage
Nice try, but it doesn't seem to work (it might be disabled on the server)
Luk
Arguably, I am a complete Apache noob so I might have done it wrong. I added it just below the DirectoryIndex line, and tried it with and without my rule.
Luk
+1  A: 

I would change hosts, you shouldn't have to have php applications state their version after the extension. It was ghetto with PHP3 and very ghetto and bad practice for php5.

While of course its possible this is bad practice and you will most likely never see an OSS application built around a php5 file extension naming convention.

I would quit while you're ahead and jump ship on a bad host - not try and alter how an application like mediawiki is built to operate. The hosts I've seen that have both php4 and php5 allow you to choose which install you would like to run for the domain - not designate it with a file extension. Thats ghetto.

Syntax
Unfortunately that's not an option :) (I agree that having .php redirecting to the previous version is not a good idea)
Luk
how come every time I read posts of people doing weird and wacky things to make things work on their webhost they won't move? if you are doing it for fun its one thing, if this is something serious, you really need to reconsider your approach, otherwise you will have rough days ahead of you.
Syntax
+1  A: 
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.php $1.php5 [R=301,L]
RewriteRule ^(.*)\.php $1.php5 [L]

I found this on the following web site which may be useful, you could make it more specific and remove the catchall to change only a certain number of .php files if you liked.

You can also customize it to suit only a certain directory using the RewriteBase condition.

Asciant
A: 

The REQUEST_URI value always starts with a slash but your pattern doesn’t.

Gumbo
A: 

This seems to work for me:

AddType application/x-httpd-php5 .php