2016-03-03 204 views
1

我想實現我需要別人的幫助下COMPLE重寫規則..阿帕奇重寫規則,太多的重定向錯誤

這裏是我的要求..

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

爲什麼** ** ^在目標路徑? – starkeen

+0

對於域名的用途,是不是必需的。 – DevOpsNewB

+0

這是你的.htaccess文件中的'RewriteRule'指令嗎? (實際上,我發現''.htaccess'標記後來被添加到了問題中,但是您的'RewriteRule'模式在.htaccess中不匹配。) – MrWhite

回答

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] 
+0

它沒有工作:(我已經更新了我的查詢部分跟蹤日誌。您能否請建議 – DevOpsNewB

+0

「跟蹤日誌」?您的意思是「沒有工作」?「太多重定向仍然」? – MrWhite

+0

它給404,請參閱更新的跟蹤日誌 – DevOpsNewB