2016-01-23 85 views
1

我目前的鏈接工作:

domain.com/folder/index.php?page=home 

,我試圖得到它這樣的:

domain.com/folder/home 

的PHP代碼,我使用讓頁面

<?php 
if (isset($_GET['page'])) { 
$page = $_GET['page']; 
} else { 
$page = 'home'; 
} 
if (strpos($page, '/') !== false || !file_exists("pages/$page.php")) { 
$page = 'error'; 
} 
include ("pages/$page.php"); 
?> 

我tryed很多可以得到正確的.htaccess代碼重寫我的網址,從發電機到論壇的帖子,但我不能得到正確的代碼。

我希望有人能讓我朝着正確的方向努力工作。

+1

我建議您發佈HTTP主機配置和'.htaccess'風格文件的內容,以便我們能夠提供幫助。我們並不真的對你發佈的基於php的路由器感興趣... – arkascha

+0

發佈你的htaccess。沒有它,我們無法真正幫助。 –

+0

「我目前的鏈接是」 - 如果您還沒有,則需要更改應用程序中的這些鏈接。 – MrWhite

回答

4

這些.htaccess規則應該幫助您開始

RewriteEngine On 
RewriteBase/

#### this allows you to write your links in the form /folder/home #### 
RewriteRule ^folder/([0-9]+)$ folder/index.php?page=$1 [NC,L] 


#### to dynamically redirect to /folder/home #### 
RewriteCond %{THE_REQUEST} /(?:index\.php)?\?page=([^&\s]+) [NC] 
RewriteRule^%1? [R=302,L,NE] 
1
Redirect ^(.*).php$ index.php?page=$1 [L,QSA] 

利用這在您的htaccess

+0

**否**!查詢字符串不能在Redirect指令中處理。 – starkeen

+1

請注意,Rediret指令不支持正則表達式,如果與支持正則表達式的RedirectMatch一起使用,您的edied代碼將在服務器上導致重定向循環錯誤。解決OP問題的更好方法是mod_rewrite。 – starkeen

+1

感謝@Starkeen將看看它。 – ameenulla0007