我正在尝试处理应用程序的多个区域,但URL未按预期重新编译。
这是.htaccess文件:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^division/(.*)/section/(.*)$ ./index.php?division=$1§ion=$2
RewriteRule ^division/(.*)$ ./index.php?division=$1
RewriteRule ^area/(.*)$ ./index.php?area=$1
期待的是什么:
如果URI匹配 division/some_division/section/some_section
重写为index.php?division=some_division§ion=some_section
如果定义了否部分(section/some_section
),请转到第二条规则 -
如果URI匹配 division/some_division
仅重写为index.php?division=some_division
如果没有分区, URI匹配 area/some_area
重写为index.php?area=some_area
我几乎可以肯定我可以将两个第一规则结合起来,我已经尝试过这个正则表达式,但它不起作用:
^division/(.*)( /section/(.*) )?$
它应该使/section/some_section
成为可选值。
不幸的是没有效果。有什么想法吗?
答案 0 :(得分:2)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^division/(.*)/section/(.*)$ ./index.php?division=$1§ion=$2 [QSA,L]
RewriteRule ^division/(.*)$ ./index.php?division=$1 [QSA,L]
RewriteRule ^area/(.*)$ ./index.php?area=$1 [QSA,L]