我重写了.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]
有没有办法让它更容易修改(一行)?
非常感谢
答案 0 :(得分: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] =>
)