Expression Engine 2 301 redirect old template group to new one

不打扰是莪最后的温柔 提交于 2019-12-24 07:28:02

问题


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?


回答1:


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();
?>



回答2:


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.



来源:https://stackoverflow.com/questions/6939098/expression-engine-2-301-redirect-old-template-group-to-new-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!