3

I have installed two CMSs in the same directory. One of the CMSs allows the index.php file to be renamed to index2.php, the other one does not. Ideally I'd like to set up a conditional rule in the .htaccess file which:

  • Uses index.php as the default DirectoryIndex
  • If there is a 404 error then set the DirectoryIndex to index2.php

Does anyone know if/how this possible?

Sam
  • 53
  • 4
  • Good question, I'm not sure if that's possible with `.htaccess`. You could fire a sub-request to the first CMS and if that returns the 404 status header, the second rule to `index2.php` applies. – hakre Oct 08 '11 at 14:19
  • Is this the best setup for your application? What about letting each CMS live in its own subdirectory... or better yet, its own virtual host? –  Oct 28 '11 at 16:53

1 Answers1

2

(404 = File Not Found), so you're actually looking for a method which allows going through a list of possible index files)
Add the following line to your .htaccess file:

DirectoryIndex index.php index2.php

When index.php exists, it's used. Otherwise, index2.php is used.
When index.php and index2.php exist, index.php is used, because it appeared first.

See also: Apache Docs > DirectoryIndex directive.

Rob W
  • 315,396
  • 71
  • 752
  • 644
  • I do not think that the OP is asking for that. I think CMS 1 should kick in at first and if it returns 404 (file not found), CMS 2 should kick in. But both CMS'es use url-aliasing. – hakre Oct 08 '11 at 14:25
  • @hakre The condition is given at the question. *`"Use index.php, if 404 then use index2.php"`*, which equals: `Use index.php if exist, else index2.php` which translates to `DirectoryIndex index.php index2.php`. – Rob W Oct 08 '11 at 14:29
  • Uhm, a 404 return status header can be returned by index.php (*"use index.php"*), and if that is the case (*"if 404 then use index2.php"*). `DirectoryIndex` does not check the response code of the subrequest AFAIK, it just executes the index script when the file exists, regardless what which response status that script would return. – hakre Oct 08 '11 at 14:51
  • Thanks for the responses, Rob - the DirectoryIndex method almost works, however both CMS's (Magento and WordPress) have url aliasing as hakre says, which causes the Magento pages to appear and the WordPress pages result in a Magento 404 page. – Sam Oct 09 '11 at 12:13