我刚刚使用 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/