A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearHow to use mod_rewrite with Zend Framework? - page 1
User InfoPosts
How to use mod_rewrite with Zend Framework?#1
I(ve just deployed a new site using Zend Framework. Due to the popularity of my tutorials I(d like to redirect any request for a tutorial to the relevant page on the new site. So far this is what I(ve got:

URL before Rewrite: http://neranjara.org/tutorials/?tid=56

URL after Rewrite: http://neranjara.org/article/id/56

The .htaccess file I(m attempting to use looks like this:


$ cat html/.htaccess
RewriteEngine on

RewriteRule tutorials/\?tid=(.*)$ /article/id/$1 [R=301]
RewriteRule !\.(js|ico|gif|jpg|png|css|xml|phps)$ index.php


But this rule is not matching any URLs ... :((

Does any one see a problem here?

posted date: 2008-12-31 10:23:00


Re: How to use mod_rewrite with Zend Framework?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-31 10:23:01


Re: How to use mod_rewrite with Zend Framework?#3
The query string (the parameters passed to your file) won(t be in the RewriteRule.Taken from http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule:The Pattern will not be matched against the query string. Instead, you must use a RewriteCond with the %{QUERY_STRING} variable. You can, however, create URLs in the substitution string, containing a query string part. Simply use a question mark inside the substitution string, to indicate that the following text should be re-injected into the query string. When you want to erase an existing query string, end the substitution string with just a question mark. To combine a new query string with an old one, use the [QSA] flag.You have two possibilities here:Remove your first RewriteRule and do the verification in your index.php instead before continuing to your framework. The initial query should be available in $_SERVER[(REQUEST_URI(] or something like that. So verify if it(s tutorials, take the tid parameter and then go on with a redirection:header("Location: http://http://neranjara.org/article/id/$id");exit();Use RewriteCond with %{QUERY_STRING} instead as stated in the Apache documentation. This solution is discussed in thread like this one.// Edit:Have a look at Chris( answer who was kind enough to detail the solution using QUERY_STRING. This is probably what you(ll want to use. Thanks Chris.

posted date: 2008-12-31 11:34:00


Re: How to use mod_rewrite with Zend Framework?#4
Zend uses all the htaccess power that htaccess can deliver so theres a very handy(chainable and interesting and not very well documented) method to achive this in the bootstrap!You must use the Zend Router in your bootstrap (index.php). Probably something like: (this would be foo.com/article/23$router = $frontController->getRouter();$route = new Zend_Controller_Router_Route( (article/:id(, array((id( => 1) ); $router->addRoute((article(, $route);More info here

posted date: 2008-12-31 11:39:00


Re: How to use mod_rewrite with Zend Framework?#5
Based on your previous entry: $ cat html/.htaccess RewriteEngine on RewriteRule tutorials/\?tid=(.*)$ /article/id/$1 [R=301] RewriteRule !\.(js|ico|gif|jpg|png|css|xml|phps)$ index.phpI(d suggest using this instead: $ cat html/.htaccess RewriteEngine on RewriteCond %{QUERY_STRING} ^tid=([^&]*) RewriteRule tutorials/ /article/id/%1 [R=301, L] RewriteRule !\.(js|ico|gif|jpg|png|css|xml|phps)$ index.php [L]BTW, this is just an example of the many things you could do using the QUERY_STRING variable in mod_rewrite. My vote goes to (lpfavreau( since this is option #2 from their answer.

posted date: 2009-01-01 21:08:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.