Let's say we have a url: http://example.com/section/my-url-title we want to enure that the {url_title} is not used in the URI. We have changed all template tags to point to the {entry_id} instead.
The issue now is we have 600+ url's listed with google. We therefore want a 301 re-direct that checks for a {url_title} and then sends a 301 header with the new URI schema using the {entry_id}
As an example of what we want to achieve, let imagine the URL is http://example.com/section/my-url-title this then re-directs to http://example.com/section/369
We set up as basic template which works as you might expect:
{exp:channel:entries}
{if '{segment_2}' == '{url_title}'}
I should re-direct {url_title} | {entry_id} -- <? echo({entry_id}); ?>
{if:else}
I should NOT re-direct {url_title} | {entry_id} -- <? echo({entry_id}); ?>
{/if}
{/exp:channel:entries}
And as you might expect a request to http://example.com/section/my-url-title outputs this into the template:
I should re-direct my-url-title | 369 -- 369
If we then test the url using the entry ID URI http://example.com/section/369 we get:
I should NOT re-direct my-url-title | 369 -- 369
...so far so good...
We then added the following php within the true part of the if statement:
<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: /{segment_1}/{entry_id}" );
die();
?>
And the template re-directs BUT we get caught in a re-direct loop. This is the same for either URLS:
http://example.com/section/my-url-title http://example.com/section/369
Both get in a re-direct loop.
We have also tried this plugin: http://blog.builtbyprime.com/php/301-redirect-for-expression-engine-2 which also seems to get stuck in a loop and disregard the if statement.
Any help or advice greatly appreciated.
p.s I'd rather avoid the task of remapping every url using googles webmaster tools.