1

我重写了部分内容.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]

有什么方法可以使它更简单(一行)更容易修改?

非常感谢

4

1 回答 1

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] => 
)
于 2013-10-16T05:20:18.977 回答