5

I have an MT site with the standard ExpressionEngine htaccess code to remove index.php and the home page works, and all other pages work if I put index.php in the URL. Without it, I get "no output file specified". It works on my local and non-MT server, so I know its an environment thing. What in the htaccess needs to be changed to make it work on MT?

<IfModule mod_rewrite.c>

# Enable Rewrite Engine
# ------------------------------
RewriteEngine On
RewriteBase /


# Use Dynamic robots.txt file
# ------------------------------
RewriteRule robots\.txt /robots.php [L]


# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/admin/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]


# Standard ExpressionEngine Rewrite
# ------------------------------
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

</IfModule>
Chad Crowell
  • 601
  • 6
  • 16
  • If you use this approach of adding a ? at the end of index.php AND you use 301 redirects to redirect old pages to new pages, you may find your redirect goes to a 404 page with the URL /?/old-page. In this case dont use 301 redirect, but use a RewriteRule. See here: http://ellislab.com/forums/viewthread/167241/#799494 – Laurence Cope Feb 20 '13 at 12:00

4 Answers4

8

Thanks to @danielcgold for the answer via twitter:

Try using this line RewriteRule ^(.*)$ /index.php?/$1 [L] and note the ? after index.php

Natetronn
  • 466
  • 3
  • 12
Chad Crowell
  • 601
  • 6
  • 16
  • Woud be great if Chad could edit the original post with the working script. It's a little unclear as to what the correct iteration is, and I would definitely like to try this .htaccess file. – Justin Kimbrell Nov 08 '12 at 04:47
  • @JustinKimbrell replace the very last line with Chad's correction. – Siebird Nov 08 '12 at 14:21
6

I posted a Gist last night with my standard rewrite rules for all my ExpressionEngine sites on (mt).

## BEGIN Expression Engine Rewrite

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteRule ^(.*)$ /index.php?/$1 [L]

## END Expression Engine Rewrite
Siebird
  • 638
  • 4
  • 13
  • I am using MediaTemple DV4 and my standard .htaccess wouldn't work after I upgraded. This answer is what solved the problem for me. – Justin Kimbrell Jan 26 '13 at 17:44
  • 1
    I just found this out last week, Plesk by default sets up servers running PHP as FastCGI, hence the `?` needed in the last rewrite rule. I was totally unaware of this until the other day. Switching back to run PHP under Apache allows the removal of the `?`. See this thread for more context on 301 issues I was having: http://expressionengine.stackexchange.com/questions/5188/301-redirects-appending-query-string/5218#5218 – Siebird Jan 27 '13 at 00:17
1

Using EE 2.7.0 and Mediatemple's Grid service (formerly "GS"), I've had luck using the standard .htaccess:

<IfModule mod_rewrite.c>
        RewriteEngine On

        # Removes index.php from ExpressionEngine URLs
        RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

but then going into the AccountCenter > [mydomain.com] > PHP Settings, and changing the PHP version from 5.5.1 CGI (latest) to 5.3.7 CGI (stable).

1

I posted this solution on the ExpressionEngine Stack Exchange site, but in a nutshell the shared hosting environment we had to use was forced to use FastCGI, and we couldn't modify any CGI or PHP configurations.

In an attempt to create the $_SERVER['PATH_INFO'] variable myself, what worked for me was this 3 step 'custom' approach:

  1. First, in ExpressionEngine > CP Home > Admin > System Administration > Output And Debugging, I set Force URL query strings to No.
  2. Next, as mentioned in previous answers, I changed the .htaccess directive from RewriteRule ^(.*)$ /index.php/$1 [L,QSA] to RewriteRule ^(.*)$ /index.php?/$1 [L,QSA] (extra ? after index.php).
  3. Finally, I added this piece of custom PHP code to the top of site root's index.php file to "force" the $_SERVER['PATH_INFO'] variable into accurate existence:

    <?php
    
        $path = $_SERVER['REQUEST_URI'];
        $pos = strpos($path, '?');
        if ($pos !== false)
            $path = substr($path, 0, $pos);
        $_SERVER['PATH_INFO'] = $path;
    
        /**
         * ExpressionEngine - by EllisLab
           ...
           ...
    

I hope this helps someone! I really pulled my hair out trying to find somewhat more elegant solutions!

Community
  • 1
  • 1
Chris Kempen
  • 9,491
  • 5
  • 40
  • 52