【问题标题】:Apache rewrite rule, too many redirects errorApache重写规则,太多重定向错误
【发布时间】:2016-03-03 11:43:37
【问题描述】:

我正在尝试实现一个重写规则,我需要有人帮助来完成..

这是我的要求..

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

【问题讨论】:

  • 为什么^在目标路径中?
  • 对于域名来说,是不是必须的。
  • 你的 .htaccess 文件中有 RewriteRule 指令吗? (其实我看到.htaccess标签后面已经添加到问题中了,但是你的RewriteRule模式在.htaccess中不匹配。)
  • 不,我在 .htaccess 中没有任何相关内容,并且不确定该标签是如何添加到我的问题中的。

标签: apache redirect mod-rewrite parameters


【解决方案1】:

RewriteRule ^/contextPath/(*) ^/contextPath?dl=$1 [R,L]

这个指令似乎有很多问题:

  • 模式(*)无效,应该是(.*)
  • 替换开头的^ 字符没有意义。 ^(插入符号)是正则表达式中字符串锚的开始。替换字符串不是正则表达式。因此,除非您的 URL 中包含文字 ^,否则应将其省略。
  • 这应该是内部重写,而不是外部重定向R 标志)。大概您不想向用户公开您的/contextPath?dl= URL?

在您的 Apache 配置中尝试如下操作:

# Internally rewrite the request providing the "dl" param is not already present
RewriteCond %{QUERY_STRING} !dl=
RewriteRule ^/contextPath/(.+) contextPath?dl=$1 [L]

【讨论】:

  • 它没有用 :( 我已经用跟踪日志更新了我的查询部分。你能建议一下
  • “跟踪日志”? “没有工作”是什么意思? “仍然有太多重定向”?
  • 我是否需要创建指令,我希望不需要,请求应该去tomcat
  • 404 可能表明这些规则/指令没有被处理。尝试在RewriteRule 上添加R 标志 - 它会重定向吗?它重定向到什么? “我需要创建指令”是什么意思?以上所有指令都称为指令
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-13
  • 1970-01-01
  • 2011-07-30
  • 2011-02-16
相关资源
最近更新 更多