php - 如何在 Zend 框架中使用 mod_rewrite?

标签 php apache zend-framework mod-rewrite

我刚刚使用 Zend Framework 部署了一个新站点。由于我的教程很受欢迎,我想将对教程的任何请求重定向到新网站上的相关页面。到目前为止,这就是我所得到的:

重写前的URL:http://neranjara.org/tutorials/?tid=56

重写后的URL:http://neranjara.org/article/id/56

我尝试使用的 .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

但是此规则不匹配任何 URL ... :'(

有人发现这里有问题吗?

最佳答案

根据您之前的条目:

  $ 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。

关于php - 如何在 Zend 框架中使用 mod_rewrite?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/403703/

相关文章:

php - mysqli bind_param() 期望是一个引用,给定值

php - 使用 AJAX 返回表中的所有记录

php - 如何仅对 url 字符串中的查询参数进行编码?

php - Zend Framework - 图像、mp3、脚本等是否放在公用文件夹中?

PHP 一次服务一页

java - 初始登录成功后,HttpGet client.execute(request) 没有响应

javascript - 使用 ShareJS 的访问控制允许来源

django - Apache 不提供来自 Django 应用程序的静态文件

php - 在模块之间共享 Zend 助手( View 或操作)

Zend_Translate 的 Mysql 适配器