当写mod_rewrite
规则,这些规则得到的顺序应用它们出现。
在你的情况,你会希望你的RedirectMatch
到之前的任何其他重写规则 —如果你removing index.php from your ExpressionEngine URLs尤其如此出现。
在您的例子,如果你只是想重定向某个目录(即ExpressionEngine模板组),下面的规则将这样做,同时允许网站的其余部分正常工作:
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect Only Matching Directories
RewriteCond %{REQUEST_URI} ^/(weddings|weddings/.*)$
RewriteRule ^(.*)$ http://www.domain.co.uk/more-weddings/$1 [R=301,L]
</IfModule>
确保该规则出现之前您的index.php(下面的例子)的去除:
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect Only Matching Directories
RewriteCond %{REQUEST_URI} ^/(weddings|weddings/.*)$
RewriteRule ^(.*)$ http://www.domain.co.uk/more-weddings/$1 [R=301,L]
# Removes ExpressionEngine index.php from URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
如果您希望Google和其他抓取工具将您的内容视为暂时移动(响应代码302,默认值)或永久移动(301),请务必正确配置RewriteRule Flags。
来源
2011-08-04 14:43:40
rjb
为什么你有美元特殊符号逃脱'\ $'?这告诉Apache寻找这个URL'/ weddings $'。在'$'之前没有反斜杠Apache将精确地查找'/ weddings'。 – LazyOne