【发布时间】:2014-04-03 18:46:11
【问题描述】:
故事:我正在开发一个网站,它在主目录中有三个子文件夹,分别是 /a/、/b/ 和 /c/。 site.com、site.com/a/、site.com/b/和site.com/c/中的内容不同;但是,代码和文件完全相似。为了减少代码量,我使用了以下.htaccess规则,并删除了/a/、/b/和/c/子文件夹中的类似代码:
RewriteRule ^(a|b|c)/(.*) $2?folder=$1 [L,QSA]
一切正常,但下面是唯一的问题。
问题:我在所有四个页面的菜单栏中都有一个搜索按钮(即site.com、site.com/a/、site.com/b/ 和site.com/c/)。当我在子文件夹页面(即site.com/a/、site.com/b/ 和site.com/c/)中搜索“hello world”之类的句子时,结果以以下格式返回:
site.com/hello-world/?folder=a
site.com/hello-world/?folder=b
site.com/hello-world/?folder=c
但是,以上搜索结果必须以以下格式返回:
site.com/a/hello-world/
site.com/b/hello-world/
site.com/c/hello-world/
有没有.htaccess 规则来解决这个问题?
【问题讨论】:
标签: .htaccess redirect directory