2009-11-09 68 views

回答

0

您可以創建一個這樣的規則。

Options +FollowSymLinks 
RewriteEngine On 

RewriteRule security-services/(.*)/? security-services.php?service=$1 [L] 

,說security-services/(.*)/?的部分URL匹配的瀏覽器並重寫爲security-services.php

關鍵部分是(.*),它捕獲該部分URL並將其作爲GET值傳遞給PHP腳本。

4

.htaccess文件,這樣的事情應該這樣做:

+0

謝謝回答! 我已經完成了你的建議並且頁面加載正常。我面臨的唯一問題是捕獲'服務'變量。 比方說,我想測試它,我會有原始示例: http://example.com/security-services.php?service=fixed-camera-surveillance 並且可以使用「echo $ _REQUEST [「服務」]「 新的例子, http://example.com/security-services/fixed-camera-surveillance 我想」固定攝像頭的監控」被回顯。 建議? – 2009-11-09 20:52:03

+0

你試過了嗎?上面的代碼實現了它,它使用'(。*)'正則表達式找到任何東西,並將它轉儲到你看到$ 1的地方,所以你的腳本在'security-services.php'文件中。 – MalphasWats 2009-11-09 21:05:09

+0

是的,我試過了,我想從網址'...'/ security-services/fixed-camera-sur中捕獲'固定攝像機監控' veillance」。我會像以前一樣詢問['service']嗎,還是隻存儲在$ 1中? – 2009-11-09 21:18:07

1

試試這個規則:

RewriteEngine on 
RewriteRule ^security-services/([^/]+)$ security-services.php?service=$1 [L] 

[^/]+介紹後/security-services(…)形成一組的比賽則可以用在替代$1引用的下一個路徑段。

如果你想要一個更一般的任何一種…-service.php文件:

RewriteEngine on 
RewriteRule ^([^/-]+)-services/([^/]+)$ $1-services.php?service=$2 [L] 
+0

感謝您的回覆! 我已經完成了你的建議並且頁面加載正常。我面臨的唯一問題是捕獲'服務'變量。 比方說,我想測試它,我會有原始示例: http://example.com/security-services.php?service=fixed-camera-surveillance 並且可以使用「echo $ _REQUEST [「服務」]「 新的例子, http://example.com/security-services/fixed-camera-surveillance 我想」固定攝像頭的監控」被回顯。 建議? – 2009-11-09 20:53:13

+0

@Mike B:這應該以同樣的方式工作,你不應該注意到任何區別。 – Gumbo 2009-11-09 21:39:52