2
我的文件夹结构,如:的.htaccess一部分是用户友好另一种是查询
- templates
- search.php
- page.php
- index.php
- index.php
这不是完整结构,但它足以让这个问题。 Index.php
有基于名为page
的第一个查询包含文件的任务。然后,通过模板类,我找到了正确的模板。 .htaccess
对于这部分看起来是这样的:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-zA-Z0-9\-]+)$ index.php?page=$1
现在来,我解决不了的部分。我有另一个查询,搜索字符串。
index.php?page=search&q=some+query
是非友好URL的示例。现在,我想让这个URL看起来像http://www.domain.com/search?q=some+query
。
我试过RewriteRule ^([a-zA-Z0-9\-]+)?q=([a-zA-Z0-9\+\%]+)$ index.php?page=$1&q=$2
但我得到了Undefined index: q in ...
。
问题是,我如何使第一个查询行为像一个静态页面,其次作为一个查询字符串从该页面行事?
这样做,非常感谢。在第一条规则结尾处追加'[L,QSA]'。 – Aleksandar
不客气,很高兴它解决了。 – anubhava