Short URL based off folder indices

  • 2
  • Idea
  • Updated 7 years ago
I don't mean to push for new features, since what makes Stacey great is its simplicity, but I feel this feature would be easy to implement and appeal to a lot of users.

The idea is that the url_to_file_path function would examine the URL to see if it was comprised of only digits. If so, it would try to match those digits with the indices of content folders.

Using the site structure the official Stacey site:
4.rss-atom-json/ would be the short url for would link to

There would need to be a new variable @shorturl.

There are a couple problems I can think of: 1. This idea does fall short for unindexed content folders like tutorials/ and download/. 2. In order to avoid conflicts between parsing long or short urls, folders cannot be named just with digits like 1.010/, 2.020/, 3.30
Photo of David DeSandro

David DeSandro

  • 8 Posts
  • 1 Reply Like

Posted 7 years ago

  • 2
Photo of Anthony Kolber

Anthony Kolber, Official Rep

  • 811 Posts
  • 157 Reply Likes
I like the idea of this, but it does have it's problems.
It also means that the short urls are referring to a page's position, rather than being an alternate permalink.
For example, if pages were reordered by number, but the names themselves stayed the same, then short urls would now point to different pages, or even straight to 404s.

What would work nicer would be a built in url shortener, which kept track of the original urls that were pointed to and returned the correct headers (ie. 301 - moved). This would be a bit more work though.
Photo of Mathew Sanders

Mathew Sanders

  • 1 Post
  • 0 Reply Likes
I've updated my file with the following code which creates the @short_url variable using the API. You'll need to register for your own API account name and key.

It's been a long time since I've written any code so if anyone can show how to clean this up would be much appreciated!

# @short_url
$full_url = ';

$ch = curl_init();
$timeout = 5;
$data = curl_exec($ch);

$page->short_url = $data;