【发布时间】:2022-01-09 23:50:40
【问题描述】:
我需要重写基于 URL 的目录:
https://example.com/subdir/gulp-service/category?parent=666&name=test
查询字符串:
?service=gulp-service&file=category&query_string=parent=666&name=test
.htaccess 应该在 https://example.com/subdir/ 中工作。
这样的.htaccess怎么写?
我想让 2 个 URL 正常工作:
https://example.com/subdir/gulp-service
和
https://example.com/subdir/gulp-service/category?parent=666&name=test
我为服务和文件写了:
RewriteEngine On
RewriteRule ^([a-z0-9\-]+)$ ?service=$1
RewriteRule ^([a-z0-9\-]+)/([a-z]+)$ ?service=$1&file=$2
在print_r($_GET)之后的PHP中我有:
Array
(
[service] => mskip-service
[file] => category
)
如何将 URL 的缺失部分添加到查询字符串中?
【问题讨论】:
-
感谢您分享您的努力,所以您的意思是您在浏览器中点击链接group.com/subdir/gulp-service/category?parent=666&name=test?哪个应该由哪个链接提供服务?你能详细说明一下吗?
-
什么是 URL 路径目标?在您的示例中,它看起来像是文档根目录?还是应该重写为相同的 URL 路径?
?service=gulp-service&file=category&query_string=parent=666&name=test- 虽然这看起来不正确,因为这会导致query_string/parent=666和name/test,这看起来好像不是意图?大概query_stringURL 参数应该包含来自初始请求的整个查询字符串?在这种情况下,它必须像?service=gulp-service&file=category&query_string=parent%3D666%26name%3Dtest一样进行 % 编码。 (?) -
是的,确实可以进行url编码,但是如何添加到查询字符串中呢?
-
大概
666和test中的parent=666&name=test是可变的?parent的值总是数字吗? URL 参数(如果有的话)总是parent=<number>&name=<something>,还是它本身可以是可变的?您的指令暗示gulp-service路径段和category路径段也是可变的?
标签: apache .htaccess mod-rewrite url-rewriting