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.

9
  • is mod_rewrite installed on the new server? Commented Aug 27, 2015 at 17:01
  • @Pipe Yes, I ran other tests to check this. Commented Aug 27, 2015 at 17:15
  • Which hosting you are using ? Commented Aug 31, 2015 at 12:07
  • @Bugfixer We are currently using an EC2 instances Commented Aug 31, 2015 at 12:07
  • @LucasFerreira - check this Commented Aug 31, 2015 at 12:12

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

Change your line with noticias:

  RewriteRule ^noticias/?$ index.php/noticias/frontend/list/ [L]

2 Comments

Still the same error, and I need the flag QSA to have access to the query string parameters.
No need to add [QSA] without new query string. But I see you have corrected your question
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.

2 Comments

It did work but I am wondering why? It happened with me apache and PHP 8.0 fast CGI
Also adding a question mark after php file name like this RewriteRule ^(.*)$ index.php?/$1 [L] solves the issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.