Routing does not work correctly

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Routing does not work correctly

alesl
Hi.

When testing a Zend Framework application at Dreamhost hosting, I discovered a problem with the routing system in my particular configuration.
At home everything works perfectly (tested on windows and linux - apache_mod), but routing does not work correctly in environmet with Apache, suexec and mod_rewrite (Dreamhost).

This is my .htaccess
RewriteEngine on

RewriteBase /

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*\.)(js|css)$ index.php [L,NC]

The second conditon rewrites js and css files to index.php where front controller takes action with defined route:
routes.jscss.type   = "Zend_Controller_Router_Route_Regex"
routes.jscss.route   = "(.+)\.(css|js)"
routes.jscss.defaults.module       = "jscss"
routes.jscss.defaults.controller = "index"
routes.jscss.defaults.action = "index"
routes.jscss.map.1  = "file"
routes.jscss.map.2  = "type"

Ass i said on local machines js, css files are minimized and send back to browser. On Dreamhost nothing hapens -> routing is ignored ?!?!

Any sugestions??

Regards, AlesL
Reply | Threaded
Open this post in threaded view
|

Re: Routing does not work correctly

weierophinney
Administrator
-- alesl <[hidden email]> wrote
(on Thursday, 21 June 2007, 10:10 AM -0700):

> When testing a Zend Framework application at Dreamhost hosting, I discovered
> a problem with the routing system in my particular configuration.
> At home everything works perfectly (tested on windows and linux -
> apache_mod), but routing does not work correctly in environmet with Apache,
> suexec and mod_rewrite (Dreamhost).
>
> This is my .htaccess
> RewriteEngine on
>
> RewriteBase /
>
> RewriteCond %{SCRIPT_FILENAME} !-f
> RewriteCond %{SCRIPT_FILENAME} !-d
> RewriteRule ^(.*)$ index.php/$1 [L]
>
> RewriteCond %{REQUEST_FILENAME} -f
> RewriteRule ^(.*\.)(js|css)$ index.php [L,NC]
>
> The second conditon rewrites js and css files to index.php where front
> controller takes action with defined route:
> routes.jscss.type   = "Zend_Controller_Router_Route_Regex"
> routes.jscss.route   = "(.+)\.(css|js)"
> routes.jscss.defaults.module       = "jscss"
> routes.jscss.defaults.controller = "index"
> routes.jscss.defaults.action = "index"
> routes.jscss.map.1  = "file"
> routes.jscss.map.2  = "type"
>
> Ass i said on local machines js, css files are minimized and send back to
> browser. On Dreamhost nothing hapens -> routing is ignored ?!?!

Is your host using mod_php, CGI, or FastCGI?

--
Matthew Weier O'Phinney
PHP Developer            | [hidden email]
Zend - The PHP Company   | http://www.zend.com/
Reply | Threaded
Open this post in threaded view
|

Re: Routing does not work correctly

jscherer26
In reply to this post by alesl
Hi,

I'm a Dreamhost hosting user and I am having routing problems too. I've hacked Zend_Controller_Request_Http public function setRequestUri to resolve my issue and have posted a question about it here http://www.nabble.com/Zend_Controller_Request_Http-setRequestUri-bug--tf3953464s16154.html

My hack is to flip the 1st and 2nd elseif condition so that $_SERVER['REDIRECT_URI'] is checked before $_SERVER['REDIRECT_URL'].

public function setRequestUri($requestUri = null)
    {
        if ($requestUri === null) {
            if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch
                $requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
==>       } elseif (isset($_SERVER['REQUEST_URI'])) {
==>           $requestUri = $_SERVER['REQUEST_URI'];
==>       } elseif (isset($_SERVER['REDIRECT_URL'])) {  // Check if using mod_rewrite
==>           $requestUri = $_SERVER['REDIRECT_URL'];
            } elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP as CGI
                $requestUri = $_SERVER['ORIG_PATH_INFO'];
                if (!empty($_SERVER['QUERY_STRING'])) {
                    $requestUri .= '?' . $_SERVER['QUERY_STRING'];
                }
            } else {
                return $this;
            }
        } elseif (!is_string($requestUri)) {
            return $this;
        } else {
            // Set GET items, if available
            $_GET = array();
            if (false !== ($pos = strpos($requestUri, '?'))) {
                // Get key => value pairs and set $_GET
                $query = substr($requestUri, $pos + 1);
                parse_str($query, $vars);
                $_GET = $vars;
            }
        }
         
        $this->_requestUri = $requestUri;
        return $this;
    }

I'm not sure if this is the solution for your problem. But if you are stuck, this maybe worth a try.

Jim

alesl wrote
Hi.

When testing a Zend Framework application at Dreamhost hosting, I discovered a problem with the routing system in my particular configuration.
At home everything works perfectly (tested on windows and linux - apache_mod), but routing does not work correctly in environmet with Apache, suexec and mod_rewrite (Dreamhost).

This is my .htaccess
RewriteEngine on

RewriteBase /

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*\.)(js|css)$ index.php [L,NC]

The second conditon rewrites js and css files to index.php where front controller takes action with defined route:
routes.jscss.type   = "Zend_Controller_Router_Route_Regex"
routes.jscss.route   = "(.+)\.(css|js)"
routes.jscss.defaults.module       = "jscss"
routes.jscss.defaults.controller = "index"
routes.jscss.defaults.action = "index"
routes.jscss.map.1  = "file"
routes.jscss.map.2  = "type"

Ass i said on local machines js, css files are minimized and send back to browser. On Dreamhost nothing hapens -> routing is ignored ?!?!

Any sugestions??

Regards, AlesL
Reply | Threaded
Open this post in threaded view
|

Re: Routing does not work correctly

alesl
In reply to this post by weierophinney
FastCGI

Matthew Weier O'Phinney wrote:
-- alesl [hidden email] wrote
(on Thursday, 21 June 2007, 10:10 AM -0700):
  
When testing a Zend Framework application at Dreamhost hosting, I discovered
a problem with the routing system in my particular configuration. 
At home everything works perfectly (tested on windows and linux -
apache_mod), but routing does not work correctly in environmet with Apache,
suexec and mod_rewrite (Dreamhost).

This is my .htaccess
RewriteEngine on

RewriteBase /

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*\.)(js|css)$ index.php [L,NC]

The second conditon rewrites js and css files to index.php where front
controller takes action with defined route:
routes.jscss.type 			   = "Zend_Controller_Router_Route_Regex"
routes.jscss.route 			   = "(.+)\.(css|js)"
routes.jscss.defaults.module 	       = "jscss"
routes.jscss.defaults.controller 	= "index"
routes.jscss.defaults.action 		= "index"
routes.jscss.map.1 			  = "file" 
routes.jscss.map.2 			  = "type" 

Ass i said on local machines js, css files are minimized and send back to
browser. On Dreamhost nothing hapens -> routing is ignored ?!?!
    

Is your host using mod_php, CGI, or FastCGI?

  
Reply | Threaded
Open this post in threaded view
|

Re: Routing does not work correctly

weierophinney
Administrator
In reply to this post by jscherer26
-- Jim Scherer <[hidden email]> wrote
(on Thursday, 21 June 2007, 11:41 AM -0700):

> I'm a Dreamhost hosting user and I am having routing problems too. I've
> hacked Zend_Controller_Request_Http public function setRequestUri to resolve
> my issue and have posted a question about it here
> http://www.nabble.com/Zend_Controller_Request_Http-setRequestUri-bug--tf3953464s16154.html
>
> My hack is to flip the 1st and 2nd elseif condition so that
> $_SERVER['REDIRECT_URI'] is checked before $_SERVER['REDIRECT_URL'].
>
> public function setRequestUri($requestUri = null)
>     {
>         if ($requestUri === null) {
>             if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first
> so IIS will catch
>                 $requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
> ==>       } elseif (isset($_SERVER['REQUEST_URI'])) {
> ==>           $requestUri = $_SERVER['REQUEST_URI'];
> ==>       } elseif (isset($_SERVER['REDIRECT_URL'])) {  // Check if using
> mod_rewrite
> ==>           $requestUri = $_SERVER['REDIRECT_URL'];

This is interesting. The check for redirect_url was added recently for
those who are using apache's 404 handling to route requests, or using
the passthrough (PT) flag in one mod_rewrite rule to pass to another.

The problem is that if we flip-flop the checks, then using 404 handling
or multiple rewrite rules would pose issues.

What is the value of REDIRECT_URL? is it empty? or another value? Could
one of you experiencing the issue give me a list of the following:

    * Actual requested URI
    * value of $_SERVER['REDIRECT_URL']
    * value of $_SERVER['REQUEST_URI']

That may help me diagnose the issue better.

Thanks!

>             } elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP
> as CGI
>                 $requestUri = $_SERVER['ORIG_PATH_INFO'];
>                 if (!empty($_SERVER['QUERY_STRING'])) {
>                     $requestUri .= '?' . $_SERVER['QUERY_STRING'];
>                 }
>             } else {
>                 return $this;
>             }
>         } elseif (!is_string($requestUri)) {
>             return $this;
>         } else {
>             // Set GET items, if available
>             $_GET = array();
>             if (false !== ($pos = strpos($requestUri, '?'))) {
>                 // Get key => value pairs and set $_GET
>                 $query = substr($requestUri, $pos + 1);
>                 parse_str($query, $vars);
>                 $_GET = $vars;
>             }
>         }
>          
>         $this->_requestUri = $requestUri;
>         return $this;
>     }
>
> I'm not sure if this is the solution for your problem. But if you are stuck,
> this maybe worth a try.
>
> Jim
>
>
> alesl wrote:
> >
> > Hi.
> >
> > When testing a Zend Framework application at Dreamhost hosting, I
> > discovered a problem with the routing system in my particular
> > configuration.
> > At home everything works perfectly (tested on windows and linux -
> > apache_mod), but routing does not work correctly in environmet with
> > Apache, suexec and mod_rewrite (Dreamhost).
> >
> > This is my .htaccess
> > RewriteEngine on
> >
> > RewriteBase /
> >
> > RewriteCond %{SCRIPT_FILENAME} !-f
> > RewriteCond %{SCRIPT_FILENAME} !-d
> > RewriteRule ^(.*)$ index.php/$1 [L]
> >
> > RewriteCond %{REQUEST_FILENAME} -f
> > RewriteRule ^(.*\.)(js|css)$ index.php [L,NC]
> >
> > The second conditon rewrites js and css files to index.php where front
> > controller takes action with defined route:
> > routes.jscss.type   = "Zend_Controller_Router_Route_Regex"
> > routes.jscss.route   = "(.+)\.(css|js)"
> > routes.jscss.defaults.module       = "jscss"
> > routes.jscss.defaults.controller = "index"
> > routes.jscss.defaults.action = "index"
> > routes.jscss.map.1  = "file"
> > routes.jscss.map.2  = "type"
> >
> > Ass i said on local machines js, css files are minimized and send back to
> > browser. On Dreamhost nothing hapens -> routing is ignored ?!?!
> >
> > Any sugestions??
> >
> > Regards, AlesL
> >
>
> --
> View this message in context: http://www.nabble.com/Routing-does-not-work-correctly-tf3960104s16154.html#a11239120
> Sent from the Zend Framework mailing list archive at Nabble.com.
>

--
Matthew Weier O'Phinney
PHP Developer            | [hidden email]
Zend - The PHP Company   | http://www.zend.com/
Reply | Threaded
Open this post in threaded view
|

Re: Routing does not work correctly

alesl
In reply to this post by jscherer26
I'm not sure if this is the solution for your problem. But if you are stuck,
this maybe worth a try.
It worked!! Thanks!

Jim Scherer wrote:
Hi,

I'm a Dreamhost hosting user and I am having routing problems too. I've
hacked Zend_Controller_Request_Http public function setRequestUri to resolve
my issue and have posted a question about it here
http://www.nabble.com/Zend_Controller_Request_Http-setRequestUri-bug--tf3953464s16154.html

My hack is to flip the 1st and 2nd elseif condition so that
$_SERVER['REDIRECT_URI'] is checked before $_SERVER['REDIRECT_URL']. 

public function setRequestUri($requestUri = null)
    {
        if ($requestUri === null) {
            if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first
so IIS will catch
                $requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
==>       } elseif (isset($_SERVER['REQUEST_URI'])) {
==>           $requestUri = $_SERVER['REQUEST_URI'];
==>       } elseif (isset($_SERVER['REDIRECT_URL'])) {  // Check if using
mod_rewrite
==>           $requestUri = $_SERVER['REDIRECT_URL'];
            } elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP
as CGI
                $requestUri = $_SERVER['ORIG_PATH_INFO'];
                if (!empty($_SERVER['QUERY_STRING'])) {
                    $requestUri .= '?' . $_SERVER['QUERY_STRING'];
                }
            } else {
                return $this;
            }
        } elseif (!is_string($requestUri)) {
            return $this;
        } else {
            // Set GET items, if available
            $_GET = array();
            if (false !== ($pos = strpos($requestUri, '?'))) {
                // Get key => value pairs and set $_GET
                $query = substr($requestUri, $pos + 1);
                parse_str($query, $vars);
                $_GET = $vars;
            }
        }
         
        $this->_requestUri = $requestUri;
        return $this;
    }

I'm not sure if this is the solution for your problem. But if you are stuck,
this maybe worth a try.

Jim


alesl wrote:
  
Hi.

When testing a Zend Framework application at Dreamhost hosting, I
discovered a problem with the routing system in my particular
configuration. 
At home everything works perfectly (tested on windows and linux -
apache_mod), but routing does not work correctly in environmet with
Apache, suexec and mod_rewrite (Dreamhost).

This is my .htaccess
RewriteEngine on

RewriteBase /

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*\.)(js|css)$ index.php [L,NC]

The second conditon rewrites js and css files to index.php where front
controller takes action with defined route:
routes.jscss.type 			   = "Zend_Controller_Router_Route_Regex"
routes.jscss.route 			   = "(.+)\.(css|js)"
routes.jscss.defaults.module 	       = "jscss"
routes.jscss.defaults.controller 	= "index"
routes.jscss.defaults.action 		= "index"
routes.jscss.map.1 			  = "file" 
routes.jscss.map.2 			  = "type" 

Ass i said on local machines js, css files are minimized and send back to
browser. On Dreamhost nothing hapens -> routing is ignored ?!?!

Any sugestions??

Regards, AlesL

    

  
Reply | Threaded
Open this post in threaded view
|

Re: Routing does not work correctly

weierophinney
Administrator
-- Aleš Lončar <[hidden email]> wrote
(on Thursday, 21 June 2007, 09:36 PM +0200):
>     I'm not sure if this is the solution for your problem. But if you are stuck,
>     this maybe worth a try.
>
>
> It worked!! Thanks!

While it may have worked, would one of you (Jim or Ales) be willing to
provide me the information I requested, so I can find a general solution
that will work for you as well as those using apache's 404 handling for
routing?

Again, I'd like to know:

  * The value of $_SERVER['REDIRECT_URL']
  * The value of $_SERVER['REQUEST_URI']
  * Actual requested URI from the browser

Hopefully then I will have enough information to make
Zend_Controller_Request_Http work properly for you *and* those using
other facilities.

Thanks!

> Jim Scherer wrote:
>
>     Hi,
>
>     I'm a Dreamhost hosting user and I am having routing problems too. I've
>     hacked Zend_Controller_Request_Http public function setRequestUri to resolve
>     my issue and have posted a question about it here
>     http://www.nabble.com/Zend_Controller_Request_Http-setRequestUri-bug--tf3953464s16154.html
>
>     My hack is to flip the 1st and 2nd elseif condition so that
>     $_SERVER['REDIRECT_URI'] is checked before $_SERVER['REDIRECT_URL'].
>
>     public function setRequestUri($requestUri = null)
>         {
>             if ($requestUri === null) {
>                 if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first
>     so IIS will catch
>                     $requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
>     ==>       } elseif (isset($_SERVER['REQUEST_URI'])) {
>     ==>           $requestUri = $_SERVER['REQUEST_URI'];
>     ==>       } elseif (isset($_SERVER['REDIRECT_URL'])) {  // Check if using
>     mod_rewrite
>     ==>           $requestUri = $_SERVER['REDIRECT_URL'];
>                 } elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP
>     as CGI
>                     $requestUri = $_SERVER['ORIG_PATH_INFO'];
>                     if (!empty($_SERVER['QUERY_STRING'])) {
>                         $requestUri .= '?' . $_SERVER['QUERY_STRING'];
>                     }
>                 } else {
>                     return $this;
>                 }
>             } elseif (!is_string($requestUri)) {
>                 return $this;
>             } else {
>                 // Set GET items, if available
>                 $_GET = array();
>                 if (false !== ($pos = strpos($requestUri, '?'))) {
>                     // Get key => value pairs and set $_GET
>                     $query = substr($requestUri, $pos + 1);
>                     parse_str($query, $vars);
>                     $_GET = $vars;
>                 }
>             }
>
>             $this->_requestUri = $requestUri;
>             return $this;
>         }
>
>     I'm not sure if this is the solution for your problem. But if you are stuck,
>     this maybe worth a try.
>
>     Jim
>
>
>     alesl wrote:
>
>
>         Hi.
>
>         When testing a Zend Framework application at Dreamhost hosting, I
>         discovered a problem with the routing system in my particular
>         configuration.
>         At home everything works perfectly (tested on windows and linux -
>         apache_mod), but routing does not work correctly in environmet with
>         Apache, suexec and mod_rewrite (Dreamhost).
>
>         This is my .htaccess
>         RewriteEngine on
>
>         RewriteBase /
>
>         RewriteCond %{SCRIPT_FILENAME} !-f
>         RewriteCond %{SCRIPT_FILENAME} !-d
>         RewriteRule ^(.*)$ index.php/$1 [L]
>
>         RewriteCond %{REQUEST_FILENAME} -f
>         RewriteRule ^(.*\.)(js|css)$ index.php [L,NC]
>
>         The second conditon rewrites js and css files to index.php where front
>         controller takes action with defined route:
>         routes.jscss.type                          = "Zend_Controller_Router_Route_Regex"
>         routes.jscss.route                         = "(.+)\.(css|js)"
>         routes.jscss.defaults.module           = "jscss"
>         routes.jscss.defaults.controller        = "index"
>         routes.jscss.defaults.action            = "index"
>         routes.jscss.map.1                        = "file"
>         routes.jscss.map.2                        = "type"
>
>         Ass i said on local machines js, css files are minimized and send back to
>         browser. On Dreamhost nothing hapens -> routing is ignored ?!?!
>
>         Any sugestions??
>
>         Regards, AlesL
>
>
>
>
>
>
>

--
Matthew Weier O'Phinney
PHP Developer            | [hidden email]
Zend - The PHP Company   | http://www.zend.com/
Reply | Threaded
Open this post in threaded view
|

Re: Routing does not work correctly

jscherer26
In reply to this post by weierophinney
Matthew,

Actual requested URI = ANY
$_SERVER['REDIRECT_URL'] =  '/index.php'
$_SERVER['REQUEST_URI'] = '/'

Here were my earlier post to try to resolve this in the order I posted them:

http://www.nabble.com/Invalid-controller-specified-%28index.php%29-tf3938224s16154.html

http://www.nabble.com/%24_SERVER-%27REDIRECT_URL%27--%3D-%27-index.php%27-tf3941470s16154.html

http://www.nabble.com/Zend_Controller_Request_Http-setRequestUri-bug--tf3953464s16154.html

If you need access to my dreamhost account or you'd like me to test something let me know.

Jim
Reply | Threaded
Open this post in threaded view
|

Re: Routing does not work correctly

jscherer26
Matthew,

I created an issue for this bug http://framework.zend.com/issues/browse/ZF-1630 and assigned it to you. This needs to be resolved before the 1.0 version or those that with this issue that try to use the MVC will fail and you don't want a lot of bad press.

Jim

Reply | Threaded
Open this post in threaded view
|

Re: Routing does not work correctly

jscherer26
In reply to this post by alesl
Matthew resolved this issue yesturday, my bad. I've tested it and it is functioning properly. Thanks,

Jim

alesl wrote
Hi.

When testing a Zend Framework application at Dreamhost hosting, I discovered a problem with the routing system in my particular configuration.
At home everything works perfectly (tested on windows and linux - apache_mod), but routing does not work correctly in environmet with Apache, suexec and mod_rewrite (Dreamhost).

This is my .htaccess
RewriteEngine on

RewriteBase /

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*\.)(js|css)$ index.php [L,NC]

The second conditon rewrites js and css files to index.php where front controller takes action with defined route:
routes.jscss.type   = "Zend_Controller_Router_Route_Regex"
routes.jscss.route   = "(.+)\.(css|js)"
routes.jscss.defaults.module       = "jscss"
routes.jscss.defaults.controller = "index"
routes.jscss.defaults.action = "index"
routes.jscss.map.1  = "file"
routes.jscss.map.2  = "type"

Ass i said on local machines js, css files are minimized and send back to browser. On Dreamhost nothing hapens -> routing is ignored ?!?!

Any sugestions??

Regards, AlesL