2012-08-23 31 views
0

我該如何着手編寫mod_rewrite的條件來使這個例子發生?重寫這樣的URL的條件

有一個URL這個像...

http://domain.com/recent/5 

渲染此頁......

http://domain.com/index.php?view=recent&page=5 

如果沒有指定頁碼(注意:我希望它有或沒有工作尾隨斜槓)...

http://domain.com/recent/ 

,則默認爲第1頁...

http://domain.com/index.php?view=recent&page=1 

但是,當有人只是去根域...

http://domain.com 

我想這個網頁渲染...

http://domain.com/index.php?view=popular&page=1 

感謝您的幫助。

回答

0

你的文檔根將這個在htaccess文件:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/([0-9]+) /index.php?view=$1&page=$2 [L,QSA] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/?$ /index.php?view=$1 [L,QSA] 
RewriteRule ^$ /index.php?view=popular&page=1 [L,QSA] 
+0

非常感謝。經過幾個小時的搜索/閱讀,我從中學到了很多東西! – Wentworth