【发布时间】:2013-09-19 08:45:37
【问题描述】:
我是 htaccess 的新手..
我有这样的条件..
如果用户访问
first/second/third
等于
first.api.php?rquest=second&attr=third
但是如果 rquest 的值为 'index',它会从 URL 中删除,比如
first/third
等于
first.api.php?rquest=index&attr=third
不是
first/index/third
我整晚都在寻找解决方案,但没有结果。 我知道如果请求是索引但 attr 有值,系统会感到困惑,它会将 attr 视为 rquest。见上文,第一/第三,系统会将“第三”段视为请求。
可以这样重写url吗?
这是我整晚的工作,我知道这仍然是废话..
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s
RewriteCond %{QUERY_STRING} !rquest=index
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ $1.api.php?rquest=$2&attr=$3 [NC]
RewriteRule ^([a-zA-Z0-9_-]+)/(.*)$ $1.api.php?rquest=$2 [QSA]
RewriteCond %{REQUEST_FILENAME} -s
RewriteCond %{QUERY_STRING} rquest=index
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ $1.api.php?rquest=index&attr=$2 [NC]
RewriteRule ^([a-zA-Z0-9_-]+)$ $1.api.php?rquest=index [QSA,L]
</IfModule>
【问题讨论】:
标签: .htaccess url mod-rewrite indexing query-string