2016-01-10 112 views
1

我有此鏈接:的.htaccess,mod_rewrite的域,子域和查詢

http://portal.tribee.com.br/pwreset.php?key=3ef73d15ddb6e307f5c12ffd5bed7d7f 

,我需要做這樣的:

http://tribee.com.br/suporte/?ccce=pwreset&key=98f7459b8d46e3a54ed76965825c894a 

由於事實上,在「pwreset .php「是其中的一個頁面......還有clientarea.php等等......如果我可以製作一個通用的htaccess讓我保留我的主域名,那將是完美的匹配......我已經嘗試過了很多組合..如:

RewriteCond %{REQUEST_URI} ^/pwreset\.php$ 
RewriteCond %{QUERY_STRING} ^key=(.*)$ 
RewriteCond %{HTTP_HOST} ^portal.tribee.com.br$ 
RewriteRule ^(.*)$ http://tribee.com.br/suporte/?ccce=&%1. [R=302,L] 
RewriteRule ^$ http://tribee.com.br/suporte/?ccce=pwreset&key=%1 [R,L] 

有沒有人有一個想法,我該如何做到這一點? TKS!

回答

0

我認爲,這個問題的答案特殊的代碼應該是這樣的:

RewriteEngine On 
RewriteBase http://tribee.com.br 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^pwreset.php?key=(.+)$ /suporte/?ccce=pwreset&key=$1 [R=302,L] 

要簡單地解釋什麼是我在這裏:

  1. 我設置的基本重寫(會將結果在基址後)
  2. 檢查請求的查詢是否不是目錄
  3. 檢查請求的查詢是否不是文件
  4. 檢查所請求的查詢包含pwreset.php?key=something和重寫的base/suporte/?ccce=pwreset&key=something
  5. 重定向到實際的重寫後的URL

我希望這有助於,否則我可能需要在代碼

+0

RewriteBase返回錯誤500頁... :(我很有信心它會是解決方案...但仍然嘗試...任何想法?Tks !! –

0

後調整的東西很多時間,我得到了它:

RewriteCond %{HTTP_HOST} ^portal.tribee.com.br$ 
RewriteCond %{REQUEST_URI} ^(.*)\.php$ 
RewriteCond %{QUERY_STRING} ^key=(\w+)$ 
RewriteRule ^(.*)\.php$ http://tribee.com.br/suporte/?ccce=$1&key=%1 [R=301,L,NC] 

如果有人在將來需要時,\w+允許我使用使用相同的名稱查詢生成的URL。感謝您的幫助喬萬尼,一遍又一遍地模擬它,並採取您的重寫規則,帶領我到答案!

+0

沒問題,很高興我幫助過 –