.htaccess 如果url不存在,请重写访问权限

.htaccess 如果url不存在,请重写访问权限,.htaccess,url,mod-rewrite,indexing,query-string,.htaccess,Url,Mod Rewrite,Indexing,Query String,我是htaccess的新手 我有一些类似的情况 如果用户访问 first/second/third 等于 first.api.php?rquest=second&attr=third 但如果rquest的值是'index',它将从URL中删除,如 first/third 等于 first.api.php?rquest=second&attr=third first.api.php?rquest=index&attr=third 不是 我整晚都在寻找解决办法,但没

我是htaccess的新手

我有一些类似的情况

如果用户访问

first/second/third
等于

first.api.php?rquest=second&attr=third
但如果rquest的值是'index',它将从URL中删除,如

first/third
等于

first.api.php?rquest=second&attr=third
first.api.php?rquest=index&attr=third
不是

我整晚都在寻找解决办法,但没有结果。 我知道,如果请求是索引,但attr有一个值,系统会感到困惑,它会像rquest一样处理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>

重新启动发动机
重写cond%{REQUEST_FILENAME}-s
重写cond%{QUERY_STRING}!rquest=索引
重写规则^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$$1.api.php?rquest=$2和attr=$3[NC]
重写规则^([a-zA-Z0-9_-]+)/(.*)$$1.api.php?rquest=$2[QSA]
重写cond%{REQUEST_FILENAME}-s
RewriteCond%{QUERY_STRING}rquest=index
重写规则^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$$1.api.php?rquest=index&attr=$2[NC]
重写规则^([a-zA-Z0-9_-]+)$$1.api.php?rquest=index[QSA,L]

尝试以下方法:

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]

不清楚您试图用旧的重写规则实现什么,但上面的内容应该符合您的描述。

嗨,Jon,谢谢您的快速响应。。我已经试过了,rquest的“索引”和attr现在已经修复了。但是另一个任务,所以它不起作用。我认为系统跳过rquest=$2,更喜欢读rquest‘index’