• Home
  • Get help
  • Ask a question
Last post 4 hours 24 min ago
Posts last week 191
Average response time last week 1 hour 50 min
All time posts 68187
All time tickets 10530
All time avg. posts per day 20

Helpdesk is open from Monday through Friday CET

Please create an (free) account to post any question in the support area.
Please check the development versions area. Look at the changelog, maybe your specific problem has been resolved already!
All tickets are private and they cannot be viewed by anyone. We have made public only a few tickets that we found helpful, after removing private information from them.

#1050 – Create alias URL programmatically

Posted in ‘sh404SEF’
This is a public ticket. Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.
Wednesday, 23 September 2015 22:44 UTC
sabroso
Hi,

I'd like to get some direction about how to generate alias URLs programmatically. I'll explain what I'm doing. I have a Joomla system plugin which changes the category of my K2 articles when the expiration date of the article is reached. K2 articles represent future events so when they expire they are moved to the past events category. So far so good.

When changing the category, obviously the article SEF URL changes since the category alias is part of the article SEF URL.

So this is what happens:

Before article expiration the SEF URL is: www.mysite.com/upcoming-events/my-event

Once expired the new SEF URL is: www.mysite.com/past-events/my-event

So I would like to add some code in my plugin so at the same time that I change the category of the article I include the old SEF URL (before expiration) as an alias of the new SEF URL (once the category change has happened).

I was looking to do an insert into the sh404sef_aliases table in the database and hope that this will create the 301 re-direct as per standard sh404sef alias behaviour. But I'm not sure that will work or whether is the best way of achieving what I'm aiming at.

I look forward to your suggestions, thanks!
Thursday, 24 September 2015 09:02 UTC
wb_weeblr
Hi

Yes, inserting items in the alias table will cause redirects to happen. You have to:

- insert the "old", "source" URL, withouth trailing slash
- insert the target URL for the redirect as a non-sef URL, starting with "index.php?option=com_k2...."
- the non-sef must have a language information - even if your site is NOT multilingual. So you should simply add, for instance "&lang=en"
- preferrably the non-sef should have the correct Itemid
- IMPORTANT: the non-sef should be sorted. That is you should use something like:
$nonSef = Sh404sefHelperUrl::sortUrl($nonSef);

before inserting the non-sef URL into the table. This ensures quick and successfull lookups.

That should be all I think.

Rgds
 
Thursday, 24 September 2015 17:14 UTC
sabroso
OK, great.

One last question, in order to call the sh404sef API and sort the nonsef URL, do I need to include any file (require once) for the API? Or can I just issue the code you provided from anywhere in Joomla?

Many thanks!
Thursday, 24 September 2015 17:15 UTC
wb_weeblr
Hi

No, sh404SEF is entirely autoloaded, you don't need anything.

Rgds
 
Thursday, 24 September 2015 17:16 UTC
sabroso
brilliant! thanks!
Thursday, 24 September 2015 18:27 UTC
wb_weeblr
You're welcome!

Closing this ticket now, feel free to open a new one as needed. If you do so, please mention this ticket number in the new one.

If you created any superadmin account for us, be sure to delete or block it now to avoid unecessary risk in the future.

Rgds
 
This ticket is closed, therefore read-only. You can no longer reply to it. If you need to provide more information, please open a new ticket and mention this ticket's number.