0

I am looking for a way to force a RewriteRule in an .htaccess file to use the result of a previous RewriteRule.

I have the following rule:

RewriteRule ^this-controller/this-action.*$ /that-controller/that-action

This would work fine, however I'm using Zend Framework which requires additional rules to route all requests to index.php for processing.

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !server-status
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

The result is the following error:

'Invalid controller specified (this-controller)'

It seems to be redirecting requests to index.php using the original url (this-controller/this-action). How can I get it to pass the rewrite url (/that-controller/that-action) to index.php instead?

5
  • You'd be better off handling this with a ZF route, or a redirect Feb 1, 2013 at 21:58
  • will that be seen by the user?
    – Matt K
    Feb 1, 2013 at 22:19
  • With a route - this-controller/this-action, with a redirect they'd see the other Feb 1, 2013 at 22:27
  • Apache rules should operate on the results of previous rules, so if your first rule were matching, the subsequent rule should get that-controller rather than this-controller (assuming it is matching as well). Can you confirm the first rule is actually matching? I would suggest setting the result to be a redirect temporarily so that you can see the results in the browser. Also setting the [L] flag so rule processing would stop and you could be sure index.php wasn't getting it. Feb 1, 2013 at 23:26
  • Zend is checking the original url, not the rewritten url. All urls are rewritten to index.php, so the only way for Zend to know the requested url, is to look at the original url. The only solution to this would be to modify something to Zend, or proxy the request by adding the [P] flag. I don't know zend, so I can't help you with the first option.
    – Gerben
    Feb 3, 2013 at 19:24

0

Your Answer

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

Browse other questions tagged or ask your own question.