2008-10-09 106 views
0

我的mod_rewrite規則有一些問題。我想要處理三種不同的網址格式。Apache - mod_rewrite重寫規則問題

  1. http://example.com/%module%/%view%-%args%.html
  2. http://example.com/%module%/%view%.html
  3. http://example.com/%module%

以下mod_rewrite的規則並沒有真正的工作 。另外我有問題,查詢(例如:user.html?foo = bar)沒有效果。

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteRule ^([0-9A-Za-z_-]*)/?([0-9A-Za-z_]+)-?([0-9A-Za-z_,]*)\.html$ index.php?__module=$1&__view=$2&__argv=$3 

    RewriteRule ^([0-9A-Za-z_-]*)/?$ index.php?__module=$1&__view=&__argv= 
</IfModule> 

回答

3

對於查詢字符串,使用QSA(Query String Append)標記您的規則。

你正在嘗試配置的稱爲「前端控制器」,其中已經有相當多的現成。也許你應該看看一些流行的PHP框架,並採用一個適合你的框架。

+0

我正在研究一個PHP5框架,因爲我喜歡編程和邊做邊學。如果您有興趣:http://code.google.com/p/quail/。我想保持簡單。 – alexvetter 2008-10-09 20:29:56