2014-07-15 63 views
1

不工作我使用PHP和Apache服務器的工作,我想重寫sites/all/themes/chap2014/fpd/gift.phpfdp/giftsites/all/themes/chap2014/fpd/another.phpfdp/another 正是我想要做到這一點重寫URL在PHP

重寫sites/all/themes/chap2014/fpd/*.phpfpd/*

重寫模式啓用,我在.htacess文件中嘗試下面的代碼。

RewriteEngine on 
RewriteRule ^fpd/?$ sites/all/themes/chap2014/fpd/$1.php 

但是什麼都沒有發生,實現這個目標的正確方法是什麼?

得到任何幫助,

回答

2

你需要URI對URI模式的LHS第一組和捕捉部分,你可以在RHS使用$1$2等之前。

RewriteEngine on 

RewriteRule ^fpd/([^/]+)/?$ /sites/all/themes/chap2014/fpd/$1.php [L,NC] 

PS:在你的問題,你都用了fpdfdp。不知道哪一個是對的。

+0

我嘗試這一點,但什麼都沒有發生在 重寫規則^ FPD /([^ /] +)/ $ 'RewriteEngine敘述? /sites/all/themes/chap2014/fpd/$1.php [L,NC]' – zhilevan

+0

我測試你的規則在http://martinmelin.se/rewrite-rule-tester/ 與此網址'網站/所有/主題/ chap2014/fpd/tshirt.php'但被告知不匹配 – zhilevan

+0

1.切勿在該網站上測試,因爲它不可靠。 2.你需要輸入你的URI爲'http:// example.com/fpd/tshirt.php',它將被內部轉發到'http://example.com/sites/all/themes/chap2014/fpd/tshirt .php' – anubhava

2

試試這個:

RewriteRule ^fpd/(.+)$ sites/all/themes/chap2014/fpd/$1.php

你可能要排除的/符號,如果是這樣,然後用[^/]+更換.+

您必須將要放入的零件放入變量(),每個封閉零件將放入$ 1,$ 2,$ 3等等。

而且,這裏是一個很好的工具來測試你重寫規則:

http://martinmelin.se/rewrite-rule-tester/

+0

我嘗試在你建議的測試,網址爲「sites/all/themes/chap2014/fpd/tshirt.php」,回報不匹配, – zhilevan

+0

@zhilevan,它不應該返回任何東西。在測試儀中鍵入'fpd/tshirt',你會看到它重寫爲'sites/all/themes/chap2014/fpd/tshirt.php'。畢竟,這就是域名後面的URL –