Php 如何在Zend框架中使用mod_rewrite?
我刚刚使用Zend Framework部署了一个新站点。由于我的教程很受欢迎,我想将任何教程请求重定向到新站点的相关页面。到目前为止,我得到的是: 重写前的URL: 重写后的URL: 我尝试使用的.htaccess文件如下所示: $ cat html/.htaccess RewriteEngine on RewriteRule tutorials/\?tid=(.*)$ /article/id/$1 [R=301] RewriteRule !\.(js|ico|gif|jpg|png|css|xml|phps)$ index.php $cat html/.htaccess 重新启动发动机 重写规则教程/\?tid=(.*)$/article/id/$1[R=301] 重写规则!\。(js | ico | gif | jpg | png | css | xml | phps)$index.php 但此规则不匹配任何URL…:'( 有人看到这里有问题吗?查询字符串(传递到文件的参数)不在重写规则中 摘自: 模式将不匹配 根据查询字符串。相反,您 必须将重写条件与 %{QUERY_STRING}变量。您可以, 但是,请在中创建URL 替换字符串,包含 查询字符串部分。只需使用 替换中的问号 字符串,以指示以下 文本应重新注入到 查询字符串。当您要删除时 在现有查询字符串中,结束 仅使用 问号。组合新查询的步骤 使用旧字符串,使用[QSA] 旗帜 这里有两种可能性:Php 如何在Zend框架中使用mod_rewrite?,php,apache,zend-framework,mod-rewrite,Php,Apache,Zend Framework,Mod Rewrite,我刚刚使用Zend Framework部署了一个新站点。由于我的教程很受欢迎,我想将任何教程请求重定向到新站点的相关页面。到目前为止,我得到的是: 重写前的URL: 重写后的URL: 我尝试使用的.htaccess文件如下所示: $ cat html/.htaccess RewriteEngine on RewriteRule tutorials/\?tid=(.*)$ /article/id/$1 [R=301] RewriteRule !\.(js|ico|gif|jpg|pn
$\u服务器['REQUEST\u URI'中可用
或类似的内容。因此,请验证它是否是教程,使用tid参数,然后继续重定向:
header("Location: http://http://neranjara.org/article/id/$id");
exit();
看看是谁用QUERY_STRING详细介绍了解决方案。这可能是您想要使用的。谢谢Chris。Zend使用了htaccess可以提供的所有htaccess功能,因此有一个非常方便(可链接、有趣且没有很好的文档记录)的方法在引导中实现这一点 您必须在引导程序(index.php)中使用Zend路由器 $router= $frontController->getRouter() $route=new Zend_控制器_路由器_路由( “article/:id”, 数组('id'=>1));$router->addRoute('article',$route)
更多信息基于您以前的条目:
$ cat html/.htaccess
RewriteEngine on
RewriteRule tutorials/\?tid=(.*)$ /article/id/$1 [R=301]
RewriteRule !\.(js|ico|gif|jpg|png|css|xml|phps)$ index.php
我建议改用这个:
$ 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]
顺便说一句,这只是使用mod_rewrite中的QUERY_STRING
变量可以做的许多事情的一个例子。我的投票结果是“lpfavreau”,因为这是他们答案中的选项2