我正在尝试实施一个重写规则,我需要别人的帮助来补充..
这是我的要求..
HTTPS://{domain}/contextPath/browse //should transformed to
HTTPS://{domain}/contextPath?dl=browse
另一个样本..
HTTPS://{domain}/contextPath/login //should transformed to
HTTPS://{domain}/contextPath?dl=login
当我尝试使用此规则时,我收到的重定向错误太多了。
RewriteRule ^/contextPath/(*) ^/contextPath?dl=$1 [R,L]
你能帮我解决这个问题吗?
- [03/Mar/2016:20:40:38 -0600] "GET /contextPath/loginall HTTP/1.1" 404 983 [Thu Mar 03 20:40:38.809774 2016] [rewrite:trace2] [pid 20144:tid 47425062725952] mod_rewrite.c(468): [rid#1ab7ae90/initial] init rewrite engine with requested uri /contextPath/loginall [Thu Mar 03 20:40:38.809805 2016] [rewrite:trace2] [pid 20144:tid 47425062725952] mod_rewrite.c(468): [rid#1ab7ae90/initial] rewrite '/contextPath/loginall' -> '/contextPath?dl=loginall' [Thu Mar 03 20:40:38.809821 2016] [rewrite:trace2] [pid 20144:tid 47425062725952] mod_rewrite.c(468): [rid#1ab7ae90/initial] local path result: /contextPath [Thu Mar 03 20:40:38.809877 2016] [rewrite:trace2] [pid 20144:tid 47425062725952] mod_rewrite.c(468): [rid#1ab7ae90/initial] prefixed with document_root to /apps/install/apache/httpd/htdocs_browser/contextPath [Thu Mar 03 20:40:38.809891 2016] [rewrite:trace1] [pid 20144:tid 47425062725952] mod_rewrite.c(468): [rid#1ab7ae90/initial] go-ahead with /apps/install/apache/httpd/htdocs_browser/contextPath [OK] [03/Mar/2016:20:40:38 -0600] 172.17.130.161 TLSv1.2 RC4-SHA "GET /contextPath/loginall HTTP/1.1" 983
答案 0 :(得分:1)
RewriteRule ^/contextPath/(*) ^/contextPath?dl=$1 [R,L]
此指令似乎存在许多问题:
(*)
无效,应为(.*)
^
字符没有意义。 ^
(插入符号)是正则表达式中字符串锚点的开头。替换字符串不是正则表达式。因此,除非您的网址中有文字^
,否则应将其省略。R
标志)。您可能不希望向用户公开您的/contextPath?dl=
网址?在Apache配置中尝试以下内容:
# Internally rewrite the request providing the "dl" param is not already present
RewriteCond %{QUERY_STRING} !dl=
RewriteRule ^/contextPath/(.+) contextPath?dl=$1 [L]