2013-03-03 25 views
0

我抨擊我的頭對着鍵盤,無法弄清楚這個問題,並且無法在google上得到答案。301重定向類別/ category/index.php到category/category.html

我有一堆舊的網址我想301重定向。例如父/子* 的index.php *必須成爲母公司* /child.html *

這是我寫:

RewriteCond %{REQUEST_URI} /index.php$ 
RewriteCond %{QUERY_STRING} ^$ 
RewriteRule ^(.*)/index.php$ $1.html? [L,R=301] 

沒有發送到索引請求.php所以這就是爲什麼我讓第二個條件爲空。 如果我在this Rewrite rule tester上測試它,它會失敗,除非我手動填充request_URI值(請參閱上面的鏈接)

我將非常感謝任何幫助。如果我解決不了,我將不得不手動做Redirect 301 oldurl newurl,這將需要很長時間!

+0

我需要添加,這是爲了joomla 2.5遷移,所以/administrator/index.php必須仍然正常運行 – Kalemanzi 2013-03-03 18:02:15

+0

似乎工作使用*重寫規則測試器*鏈接到。哪裏不對?考慮發佈剩下的'.htaccess'指令,這些規則的執行順序可能會有問題。 – kjetilh 2013-03-03 19:18:02

回答

0

你可以在根目錄中的一個.htaccess文件試試這個:

Options +FollowSymlinks -MultiViews 
RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+)/index\.php/? [NC] 
RewriteRule .*    /%1/%2.html    [R=301,L] 

地圖默默

http://example.com/parent/child/index.php

http://example.com/parent/child.html

字符串parent和假設是可變的,而index.php被假定爲固定的。

對於無聲映射,替換[R = 301,L]與[L]

這適用於一個真實服務器。但是,您可以在沒有%{REQUEST_FILENAME}條件的情況下對其進行測試here,但不支持該測試站點。