0

我是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>
4

1 回答 1

0

尝试这样的事情:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ /$1.api.php?rquest=$2&attr=$3 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ /$1.api.php?rquest=index&attr=$2 [L,QSA]

不清楚你试图用你的旧重写规则来实现什么,但上面应该做你所描述的。

于 2013-09-14T22:53:59.450 回答