2011-08-04 40 views
1

我认为这很简单,但是我遇到问题会将旧模板组永久重定向到新模板组。表达式引擎2 301将旧模板组重定向到新模板

我有www.domain.co.uk/weddings需要指向www.domain.co.uk/more-weddings

这两个模板组都存在,不确定是否需要删除旧模板组?或模板首选项中的其他设置?

这是我一直在尝试使用:

RedirectMatch 301 ^/weddings\$ http://www.domain.co.uk/more-weddings 

我有一个正在过负载更多重定向,这个新的一个需要放在上面呢?

+1

为什么你有美元特殊符号逃脱'\ $'?这告诉Apache寻找这个URL'/ weddings $'。在'$'之前没有反斜杠Apache将精确地查找'/ weddings'。 – LazyOne

回答

3

你可以在较旧的模板(婚礼/指数)启用PHP,并将这个在它:

<?php 
    header('HTTP/1.1 301 Moved Permanently'); 
    header('Location: http://www.domain.co.uk/more-weddings'); 
    exit(); 
?> 
+0

完美的答案 - 对我来说就像一个魅力 – Trent

0

当写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

Apache mod_rewrite Cheat Sheet