开发者

Expression Engine 2 301 redirect old template group to new one

I thought this would be pretty simple, however I am having issues permanently redirecting an old template group to a new one.

I have www.domain.co.uk/weddings which needs to be directed to www.domain.co.uk/more-weddings.

Both template groups exist, not sure if I need to delete the old one too? Or any other settings in the template preferences?

Here's what开发者_开发问答 I have been trying to use:

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

I have a load more redirects which are working too, does this new one need to be placed above them?


You could enable PHP in the older template (weddings/index) and place this in it:

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


When writing mod_rewrite rules, the rules get applied in the order that they appear.

In your case, you'd want your RedirectMatch to appear before any other rewrite rules — this is especially true if you're removing index.php from your ExpressionEngine URLs.

In your example, if you only want to redirect a certain directory (i.e. an ExpressionEngine template group), the following rule will do so, while allowing the rest of the site to function normally:

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

Make sure this rule appears before your removal of index.php (example below):

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

If you want Google and other crawlers to see your content as temporarily moved (Response code 302, the default) or permanently moved (301), be sure to configure the RewriteRule Flags appropriately.

Expression Engine 2 301 redirect old template group to new one

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜