使用RewriteRule帮助创建URI重写

时间:2010-11-26 16:34:53

标签: apache url mod-rewrite rewrite

我正在使用它进行重写

RewriteRule ^site/(.*) index.php?rewrite=$1 [L]
RewriteRule (.*)\.xml(.*) $1.php$2 [nocase] 

我开始将这个站点转换为psuedo mvc系统并且真的需要上面的内容来阅读

1. If the directory is NOT ^site/public/* OR ^site/assets/* or (etc) then re-write the url as index.php?rewrite=$1  (I'm basically trying to replicate the first rule above for all cases except a couple).
2. ALSO, go ahead and rewrite all .xml pages to be changed to .php

1 个答案:

答案 0 :(得分:1)

您可以调整第一条规则以防止在这些特定情况下应用它:

# Only apply the rule when the captured section does not start
# with public/ or assets/
RewriteCond $1 !^(public|assets)/
RewriteRule ^site/(.*) index.php?rewrite=$1 [L]

似乎第二条规则已经达到了你所期望的水平,所以如果情况并非如此,你需要详细说明问题所在。