2010-07-31 100 views
0

我在爲某些網址做重定向時遇到問題,那些來自舊網站的網址有一個?登錄,不會重定向,其他每個網址都會執行。 例如: OLD: /laser-alignment-resources/presentations.cfm?pres=diaphragm.htaccess使用動態網址重定向

新: http://www.acquip.com/en/presentations/47-presentation-internal-laser-diaphragm-alignment

都不行,我相信我做錯了什麼事,但我是一個的n00b當涉及到的.htaccess

所有網址都在相同的格式,14總數:

OLD:/laser-alignment-resources/presentations.cfm PRES =氣體 新:http://www.acquip.com/en/presentations/48-presentation-gas-turbine-thermal-alignment

OLD:/laser-alignment-resources/presentations.cfm?pres=train 新:http://www.acquip.com/en/presentations/49-presentation-complete-machine-train-alignment

任何幫助將不勝感激。

回答

0

你的問題並不清楚你如何試圖在你的.htaccess文件中執行重定向,所以下次我建議你張貼一些你已經試過的代碼樣本,以便我們可以幫助你更輕鬆。

基於Apache的標籤和您所描述的問題,我會假設你使用mod_alias雖然試圖做這樣的事情:

Redirect 301 /laser-alignment-resources/presentations.cfm?pres=diaphragm http://www.acquip.com/en/presentations/47-presentation-internal-laser-diaphragm-alignment 

這不工作,雖然,因爲Redirect指令似乎只檢查請求的路徑部分,而不是查詢字符串。

如果您有mod_rewrite可用,則可以爲需要根據查詢字符串重定向的網址設置重寫規則。這看起來像這樣:

RewriteEngine On 

RewriteCond %{QUERY_STRING} =pres=diaphragm 
RewriteRule ^laser-alignment-resources/presentations\.cfm$ http://www.acquip.com/en/presentations/47-presentation-internal-laser-diaphragm-alignment [R=301,L] 

RewriteCond %{QUERY_STRING} =pres=gas 
RewriteRule ^laser-alignment-resources/presentations\.cfm$ http://www.acquip.com/en/presentations/48-presentation-gas-turbine-thermal-alignment [R=301,L] 

...等等。您可以保留您當前正在使用的Redirect報表,因爲它們應該與這些規則並行良好地工作。

+0

對不起,如果我不清楚,但你實際上已經發現它很好,我使用301重定向而不是mod_rewrite。 我剛剛嘗試使用mod_rewrite,它也不能正常工作。 我打電話給託管公司,他們說他們在他們的服務器上啓用了mod_rewrite。 它還能是什麼? – Terumo 2010-08-04 16:47:50

+0

沒問題,我只是想確保我提供了一個對你有用的答案。至於它不工作,我不知道爲什麼它不應該,但我今天下班後會進行調查,看看我能否提出一個替代解決方案。 – 2010-08-05 10:28:01

+0

@Terumo - 嗯,它可以在我的測試服務器上正常工作。當您訪問連接了查詢字符串的URL時,什麼都不會發生?你可以測試'mod_rewrite'通常使用像'RewriteRule^rewrite-test $ http://stackoverflow.com/ [R = 301,L]'這樣的規則並轉到那個'rewrite-test' URL並看到如果你被重定向到堆棧溢出。 – 2010-08-06 04:06:43