2011-07-29 126 views
0

我想用htaccess製作漂亮的網頁。.htaccess漂亮的網址

我只有一個變量 - ID。所以頁面就像index.php?id = 1,index.php?id = 2等 我想他們是:/ 1 /,/ 2/- 像文件夾,而不是ID變量...

我該如何做到使用htaccess重寫網址?

我試圖做這樣的:

<IfModule mod_rewrite.c> 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule ^([^/]+) index.php?id=$1[L] 
</IfModule> 
+1

您的似乎在工作......是否有任何錯誤?也許改成'RewriteRule ^([^ /] +)/ $ index.php?id = $ 1 [L]'(在規則末尾加'/ $',在'[L]'之前加一個空格) – arnep

+0

它給了我對象沒有找到,404錯誤......並且你的提示不會改變它... –

+0

嘗試'/ index.php'而不是'index.php'。當你使用'/ 1 /'時,它沒有在你的www-root路徑中查看,而是在/ 1 /路徑中。請參閱您的apache error.log以獲取有關錯誤的更多詳細信息。 – arnep

回答

0

這個工作對我來說:

RewriteEngine On 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule ^([^/]+) index.php?id=$1 [L] 

如果index.php文件是這樣的:

<?php 
import_request_variables('g', 'req_'); 
var_dump($req_id); 

並且您提出要求http://domain/1

然後index.php具有變量req_id = 1(因爲import_request_variables調用)