URL重写字符截断问题php .htaccess文件

时间:2017-10-23 13:17:48

标签: .htaccess url url-rewriting

要求
在.htacess文件中配置可选的多参数URL模式。

问题说明 参数值被截断如下(检查输出网址,它的键值[api = item& act = s])
输入: http://localhost/nFoodApp/items/get
输出网址
/nFoodApp/index.php?api=item&act=s&menu=g&category=e&type=t&item =

基于参数传递的预期输出
输入: http://localhost/nFoodApp/items/get
输出网址 /nFoodApp/index.php?api=items&act=get&menu=&category=&type=&item =

OR

输入: nFoodApp / items / get / 1
输出网址 /nFoodApp/index.php?api=items&act=get&menu=1&category=&type=&item =

OR

输入: nFoodApp / items / get / 1/1
输出网址 /nFoodApp/index.php?api=items&act=get&menu=1&category=1&type=&item =

我的.htacess文件

RewriteEngine On

RewriteBase /nFoodApp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/\.]+)/?([^/\.]+)/?([^/]+)/?([^/]+)/?([^/]+)/?(.*)$ index.php?api=$1&act=$2&menu=$3&category=$4&type=$5&item=$6 [L,QSA]

对于研究人员来说,以上是使用*。()[] / $ ^ [L,QSA,R = 301,所有可能的组合/模式经过数小时的谷歌搜索,试验和运行后创建的htacess文件。但是,谷歌搜索却无法解决这个问题。

如果所有参数都通过了,则工作正常 使用所有参数输入: // localhost / nFoodApp / items / get / 1/1/1/1 输出:api = items& act = get& menu = 1& category = 1& type = 1& item =

可能无法清楚地解释问题,但示例清楚地说明了.htaccess片段中显示的问题和配置。

提前致谢

1 个答案:

答案 0 :(得分:0)

尝试使用以下内容更改最后一行:

RewriteRule ^/?([^/.]+)(?:/([^/.]+)(?:/([^/]+)(?:/([^/]+)(?:/([^/]+)(?:/(.*))?)?)?)?)?$ index.php?api=$1&act=$2&menu=$3&category=$4&type=$5&item=$6 [L,QSA]