2013-10-16 292 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