2013-10-16 88 views
1

我已經重寫.htaccess狀部分:的.htaccess正則表達式簡化

RewriteRule ^content/([^/]+)/([^/]+)/?$ /index.php?section=clanky&page=$1&id=$2 [L] 
RewriteRule ^content/([^/]+)/?$ /index.php?section=clanky&page=$1 [L] 
RewriteRule ^content/?$ /index.php?section=clanky [L] 

有沒有什麼辦法讓它simplier(一行),以更容易修改?

非常感謝您

回答

1

只要你不介意在你的PHP $_GET陣列坯料參數,你可以這樣做:

RewriteRule ^content/?(?:([^/]+)/?|)(?:([^/]+)/?|)$ /index.php?section=clanky&page=$1&id=$2 [L] 

這意味着如果URI是這樣的:

/content/123/asd 

$_GET陣列將是:

Array 
(
    [section] => clanky 
    [page] => 123 
    [id] => asd 
) 

如果是這樣的:

/content/qwe 

您將獲得:

Array 
(
    [section] => clanky 
    [page] => qwe 
    [id] => 
) 

而且如果它是:

/content/ 

則:

Array 
(
    [section] => clanky 
    [page] => 
    [id] => 
) 
+0

太好了,謝謝。 所以在PHP中,我將'只'使用!empty()而不是isset()。 – Gomi