我有一个适用于我的索引页面的重写规则
RewriteRule ^index$index.php [L]
RewriteRule ^index/$index.php [L]
RewriteRule ^index/page/(0?[1-9]|1[0-2])$index.php?recordstart=$1 [L]
RewriteRule ^index/page/(0?[1-9]|1[0-2])/$index.php?recordstart=$1 [L]
我有6页有类似的情况.
例如.
RewriteRule ^graduate$graduate.php [L]
RewriteRule ^graduate/$graduate.php [L]
RewriteRule ^graduate/page/(0?[1-9]|1[0-2])$graduate.php?recordstart=$1 [L]
RewriteRule ^graduate/page/(0?[1-9]|1[0-2])/$graduate.php?recordstart=$1 [L]
我正在寻找一个可以匹配六个确切场景的重写,而不是重复四行六次.
谢谢
解决方法:
就像是:
RewriteRule ^(scenario1|scenario2|scenario3)$$1.php [L]
RewriteRule ^(scenario1|scenario2|scenario3)/$$1.php [L]
RewriteRule ^(scenario1|scenario2|scenario3)/page/(0?[1-9]|1[0-2])$$1.php?recordstart=$2 [L]
RewriteRule ^(scenario1|scenario2|scenario3)/page/(0?[1-9]|1[0-2])/$$1.php?recordstart=$2 [L]
感觉很脏,但如果你想排除所有其他情况,除了提到的情况.
编辑:我也在这里添加它,你可以通过检查/用一个删除2行规则?在它之后,它将匹配或不跟踪尾随/.解决方案将成为:
RewriteRule ^(scenario1|scenario2|scenario3)/?$$1.php [L]
RewriteRule ^(scenario1|scenario2|scenario3)/page/(0?[1-9]|1[0-2])/?$$1.php?recordstart=$2 [L]
标签:apache,php,regex,url-rewriting
来源: https://codeday.me/bug/20190530/1187107.html