8

My client's website is currently running on a apache server with mod_php. All application's routes are defined in the .htaccess file (see the code below). Now he is trying to migrate to an server running apache and php-fastcgi, but the routes are no long working.

<IfModule mod_rewrite.c>

  RewriteEngine On

  # Redirect
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} -s [OR]
  RewriteCond %{REQUEST_FILENAME} -l [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^.*$ - [NC,L]
  RewriteRule "^noticias/?$" index.php/noticias/frontend/list/ [L,QSA]
  RewriteRule ^.*$ index.php [NC,L]

</IfModule>

When I access http://domain.tld/noticias, I get No input file specified, and in the apache error_log [fcgid:warn] mod_fcgid: stderr: PHP Warning: Unknown: function '1' not found or invalid function name in Unknown on line 0, but if I access the route directly http://domain.tld/index.php/noticias/frontend/list/ it works fine.

UPDATE

I found a working solution changing some of the framework behaviour. If someone has a solution without having to change the framework (probably in the apache or php configuration), I will gadly award the answer the bounty.

Lucas Ferreira
  • 858
  • 8
  • 18

3 Answers3

5

As sugested by @user3584460, I decided to change all my routes to pass the desired controller/action as a querystring parameter. Here how it was done.

I changed all routes to pass a _url parameter:

RewriteRule "^noticias/?$" index.php?_url=/noticias/frontend/list/ [L,QSA]

This way I would not get the error "No input file specified", but the framework (zend) would not recognize the route, and would always show the homepage.

The route dispatcher expected the $requestUri variable to be in the format index.php/module/controller/action, but with the change in the .htaccess, it was index.php?_url=/module/controller/action. So I had to make some changes in the Zend_Controller_Request_Http class, so it would make the conversion.

So I added the following lines to the setRequestUri method:

public function setRequestUri($requestUri = null)
{
    // ...

    // begin changes
    preg_match('/_url=([a-zA-Z0-9\/\-_\.]+)&?(.*)/', $requestUri, $matches);
    if (count($matches) == 3)
        $requestUri = '/index.php' . $matches[1] . '?' . $matches[2];
    // end changes

    $this->_requestUri = $requestUri;
    return $this;
}

Now it works fine.

Lucas Ferreira
  • 858
  • 8
  • 18
2

Change your line with noticias:

  RewriteRule ^noticias/?$ index.php/noticias/frontend/list/ [L]
Croises
  • 18,570
  • 4
  • 30
  • 47
2

We sometimes see this on sites that use rewrites. We fixed this by changing the rewrite. The old line would be something like:

RewriteRule ^(.*)$ _routing.php/$1 [L]

We changed it into:

RewriteRule ^(.*)$ _routing.php [L]

This resolved the issue.

Rudy Broersma
  • 227
  • 1
  • 4
  • 7
  • It did work but I am wondering why? It happened with me apache and PHP 8.0 fast CGI – HADI Nov 25 '22 at 01:03
  • Also adding a question mark after php file name like this `RewriteRule ^(.*)$ index.php?/$1 [L]` solves the issue – HADI Nov 25 '22 at 01:07