Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex mod_重写为拆分/剥离URL_Regex_Apache_Mod Rewrite - Fatal编程技术网

Regex mod_重写为拆分/剥离URL

Regex mod_重写为拆分/剥离URL,regex,apache,mod-rewrite,Regex,Apache,Mod Rewrite,出于特定目的,我需要能够从URL中获取前2条路径作为用户名/md5sum'ed密码,并让Web服务器处理其余的路径 例如: h、 .ps://192.168.5.6/user/password/->应调用/pkg/index.php?u=user&p=password h、 .ps://192.168.5.6/user/password/pack/test.zip->should call/pkg/pack/dl.php?u=user&p=password&f=test.zip h、 .ps:/

出于特定目的,我需要能够从URL中获取前2条路径作为用户名/md5sum'ed密码,并让Web服务器处理其余的路径

例如: h、 .ps://192.168.5.6/user/password/->应调用/pkg/index.php?u=user&p=password h、 .ps://192.168.5.6/user/password/pack/test.zip->should call/pkg/pack/dl.php?u=user&p=password&f=test.zip

h、 .ps://192.168.5.6/user/password/images/default.png->should call/pkg/images/default.png

/pkg/index.php可能引用位于/pkg下的一组其他文件-不应修改这些URL。。 我假设可以使用$_SERVER['REQUEST_URI']获取原始完整的URI,并且我可以从中获取可能在get请求中传递到原始URL h..ps://192.168.5.6/user/password/?parm1=x&parm2=y的任何参数

当然,如果URL上没有给出user/pass组合,它只会调用h..ps://192.168.5.6/index.php


有人能告诉我如何在Apache中使用mod_rewrite来获取此信息吗?

尝试将名为.htaccess的文件添加到站点的根目录,并将其添加到文件中:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ /pkg/pack/dl.php?u=$1&p=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.-]+)$ /pkg/pack/dl.php?u=$1&p=$2&f=$3
这将打开mod_重写引擎,然后触发静默重写,这不会将访问者在web浏览器中看到的URL从/user/pass/pattern修改为dl.php脚本的双参数版本,从/user/pass/file模式修改为dl.php脚本的三参数版本

上述模式允许在用户名和密码中显示字母、数字、下划线和连字符,并允许在文件名中显示句点。如有必要,修改模式以允许添加或拒绝某些字符