0

I have two types of urls for each posting on my EE5-installation, namely

www.xy.com/blog/singlepage/url_title

www.xy.com/blog/singlepage/entry_id 

The reason for this doubling lies back in ancient times, I want to remove this.

Is it possible to somehow redirect all

www.xy.com/blog/singlepage/entry_id

to

www.xy.com/blog/singlepage/url_title

?

Another one had the problem other way round, but I am not sure if the answer to his question is fitting my needs. Another idea would be to use the addon Detour, but I am not sure if this could do the trick. Also I would prefer to do it without a plugin if possible.

I would appreciate help very much, thanks!

2 Answers 2

1

It would be possible, if you don't mind doing a page reload as part of the process.

EE can find an entry with just the url_title or entry_id, so all you need to do is create a default template that is loaded in response to the url form blog/singlepage (e.g. by creating a template group blog and putting within it a template singlepage.html) and put in that template something like this...

{if segment_3 && segment_3 ~ "/^[0-9]*$/"} // segement_3 is a number - so probably an entry_id
   {exp:channel:entries entry_id='{segment_3}' dynamic='no'}
        {redirect='blog/singlepage/{url_title}' status_code='301'}
   {exp:channel:entries}
{/if}

// otherwise we probably have url_title so try loading the normal template

{exp:channel:entries url_title='{segment_3}'}
... template stuff ...
{/exp:channel:entries}

HTH

3
  • Thanks, this looks plausible! But this means that the page first loads and then redirects (probably this is what you mean with "reload as part of the process"), am I right?
    – BNetz
    Oct 18, 2020 at 15:15
  • Yes - for pages with an entry_id rather than url_title you'd have to reload the page. There are other options, but they extend beyond EE - for example you could put in some javascript to rewrite the URL to be the one you want instead of reloading the page, and then just process the page using entry_id rather than url_title... but imagine you knew that anyway and assumed you wanted an EE based solution. Oct 19, 2020 at 9:01
  • Yes, I wanted an EE based solution. Sadly a reload does not come into consideration due to performance and search-engine-reasons. Anyhow thanks for your help!!
    – BNetz
    Oct 19, 2020 at 16:58
0

If you want to redirect your entry_id URL's JCOGS solution is good because you keep it to using native EE functionality and it's easy to remove when you no longer need it. Additionally you get a proper 301 added to the redirect to tell search engines the new location for the page so they can reindex.

You could always add redirects to .htaccess or use Detour Pro but either way you'll still have a page redirect!

2
  • If you add a 301-redirect to the htaccess the redirect will be executed before the page loads. This never is a problem for performance or SEO-issues. The problem with JCOGS' solution is that the page loads, then redirects and then loads again.
    – BNetz
    Oct 24, 2020 at 6:08
  • Yes that's correct, with the template based solution you'd get a few milliseconds before the redirect fires, htaccess redirects also take a short time to process as well so in practice your visitors would have the same whatever way is used. I've used template redirects many times with no effect on search indexing so there shouldn't be any SEO issues, the 301 redirect is the important bit. Oct 25, 2020 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.