2015-07-06 106 views
1

我要像重寫URL擴展

http://www.example.com/keyword-city.php 

的URL改寫爲

http://www.example.com/keyword-city/ 

有任何簡單的解決方案,這樣做嗎?

編輯: 我需要一個動態的解決方案。例如:

http://www.example.com/keyword1-city.php 
http://www.example.com/keyword2-city.php 
http://www.example.com/keyword3-city.php 

http://www.example.com/keyword1-city/ 
http://www.example.com/keyword2-city/ 
http://www.example.com/keyword3-city/ 

回答

-1

這很簡單:

$url = 'http://www.example.com/keyword-city.php'; 
echo str_replace('.php', '/', $url); 
+0

的OP需要mod-rewrite的解決方案,而不是PHP。 – Glorfindel

2

添加.htaccess文件與您的項目在這個文件中添加以下代碼:

RewriteEngine on 
RewriteRule ^/?Some-text-goes-here/([0-9]+)$ /.php 
+0

感謝您的回答。有沒有辦法做到這一點與變量?我得到了約200個文件,該模式爲「keyword-city.php」,「keyword1-city.php」,我想將所有文件重新寫入「/ keyword-city/ – Boeringer

+0

」。 /如果有任何其他文件像「關鍵字城市.php」現在你可以重寫沒有擴展名,但它很複雜的所有文件重寫像一個「關鍵字城市」 –

+0

我真的不明白你的評論。在帶有模式text-text.php的所有頁面上將「.php」改爲「/」? – Boeringer