在MediaTemple上使用ExpressionEngine去除index.php后出现“未指定输入文件”的错误

5

我有一个使用ExpressionEngine的MT站点,它有标准的htaccess代码来删除index.php,首页可以正常访问,但是如果在URL中不加入index.php,其他页面会显示"no output file specified"。我知道这是环境问题,因为在我的本地和非MT服务器上都可以正常工作。那么htaccess文件需要做哪些更改才能使它在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>

如果您使用在index.php末尾添加?的方法,并且使用301重定向将旧页面重定向到新页面,您可能会发现重定向会跳转到一个URL为/?/old-page的404页面。在这种情况下,请不要使用301重定向,而是使用RewriteRule。请参见此处: http://ellislab.com/forums/viewthread/167241/#799494 - Laurence Cope
4个回答

8

感谢@danielcgold通过Twitter提供的答案:

尝试使用此行 RewriteRule ^(.*)$ /index.php?/$1 [L],请注意在index.php后面有一个?


希望 Chad 能够编辑原始帖子并附上可行的脚本。现有信息不够清晰,我想尝试使用这个 .htaccess 文件。 - Justin Kimbrell
@JustinKimbrell 将最后一行替换为 Chad 的更正。 - Siebird

6

昨晚我在(mt)上发布了一个Gist,其中包含我所有ExpressionEngine网站的标准重写规则。

## 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

我正在使用MediaTemple DV4,升级后我的标准.htaccess无法正常工作。这个答案解决了我的问题。 - Justin Kimbrell
1
我上周才发现,Plesk默认将运行PHP的服务器设置为FastCGI,因此在最后一个重写规则中需要?。直到前几天我才完全不知道这一点。切换回在Apache下运行PHP可以删除?。有关我遇到的301问题的更多上下文,请参见此线程:http://expressionengine.stackexchange.com/questions/5188/301-redirects-appending-query-string/5218#5218 - Siebird

1

我使用EE 2.7.0和Mediatemple的Grid服务(以前称为“GS”),在编程方面,使用标准的.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>

然后进入AccountCenter > [mydomain.com] > PHP设置,将PHP版本从5.5.1 CGI(最新)更改为5.3.7 CGI(稳定版)


1
我在ExpressionEngine Stack Exchange网站上发布了this solution,但简言之,我们必须使用共享托管环境,并且被迫使用FastCGI,我们无法修改任何CGI或PHP配置。
为了自己创建$_SERVER['PATH_INFO']变量,我尝试使用这个3步“自定义”方法:
  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
           ...
           ...
    

我希望这能帮助到某些人!我真的为寻找更加优雅的解决方案而苦恼不已!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接