![Apache 重写规则](https://linux22.com/image/570781/Apache%20%E9%87%8D%E5%86%99%E8%A7%84%E5%88%99.png)
顺便问一下,我该如何结合这两条规则,
RewriteRule (.*)/(.*) $1/consumerDSLWGP/$2
RewriteRule (.*)/dsl/(.*) $1/consumerDSLWGP/$2
即,空上下文路径或 /dsl 上下文路径必须替换为 /consumerDSLWGP。我试过了
(.*)/(dsl)?/(.*)
但显然甚至 /dsl 也被附加在 URL 中。
115.241.55.20 - - [22/Dec/2011:10:20:47 --0500] [superclientstg2.sl.ca/sid#8fd3260][rid#9101a88/initial] (2) explicitly forcing redirect with https://superclientstg2.sl.ca/consumerDSLWGP/consumerDSLWGP/consumerDSLWGP/.../dsl
115.241.55.20 - - [22/Dec/2011:10:20:47 --0500] [superclientstg2.sl.ca/sid#8fd3260][rid#9101a88/initial] (1) escaping https://superclientstg2.sl.ca/consumerDSLWGP/.../dsl for redirect
115.241.55.20 - - [22/Dec/2011:10:20:47 --0500] [superclientstg2.sl.ca/sid#8fd3260][rid#9101a88/initial] (1) redirect to https://superclientstg2.sl.ca/consumerDSLWGP/.../dsl [REDIRECT/302]
答案1
这次重写应该可以实现你想要的效果:
RewriteRule (/dsl)?/redirect.jsp /DSLWGP/dnsredirect.jsp
你可能会发现这只 cheetsheat有帮助的。
根据以下评论更新:
RewriteRule (.*)/dsl/(.*) $1/consumerDSLWGP/$2
重写规则模式中括号内匹配的任何内容都可以在替换中引用为 $[number],其中 [number] 是与您想要的括号集相对应的数字。
答案2
类似这样的事情应该可以工作:
RewriteEngine On
RewriteCond %{QUERY_STRING} jsplang=(en|fr){1}
RewriteCond %{REQUEST_URI} !^(/DSLWGP/)
RewriteRule /(dsl/)?redirect\.jsp http://%{HTTP_HOST}/DSLWGP/dnsredirect.jsp?lang=%1
如果不起作用:
两个提示:
请尝试使用该RewriteLog
指令:它可以帮助您追踪此类问题:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On
我可以请您在问题中添加重写日志吗?
我最喜欢的检查正则表达式的工具:
http://www.quanetic.com/Regex(不要忘记选择 ereg(POSIX)而不是 preg(PCRE)!)