我想创建一系列mod_rewrite规则来制作漂亮的url。.htaccess mod_rewrite challenge
我想就可以提供index.php?section=123&area=345&option=1 as /123/345/option=1
到目前为止好,这个工程:
RewriteRule ^(.+)/(.+)/(.+)$ /index.php?section=$1&area=$2&$3
确定这里是我的第一个问题:
如何强制它,如果工作其中一个变量没有定义,即。如果有人浏览到
/section
而不是/section/area/
。如果它已被关闭,我可以使htaccess自动创建/area/
作为默认值吗?同样,我如何强制
/area/
有斜线?如果目前没有斜线,我会得到一个404,因为系统正在寻找但没有找到第三个变量。
谢谢这很好地指出了我的正确方向。为了清晰起见,我最终将不同的规则分开了,但是这基本上是对代码的修改: 'RewriteRule ^(。+)/(。+)/(。+)$ /index.php?section=$1&area = $ 2&$ 3 [L] RewriteRule ^(。+)/(。+)/ $ /index.php?section=$1&area=$2 [L] RewriteRule ^(。+)/(。+)$/index .php?section = $ 1&area = $ 2 [L] RewriteRule ^(。+)/ $ /index.php?section=$1 [L]' 这涉及尾部斜线问题,我将使用PHP来定义如果需要的话,默认区域。 – whizzkid 2011-12-22 01:18:55