Using YOURLS in a Subdirectory – Revisited

I’ve written before about how to use the YOURLS URL shortener from a subdirectory. In fact, I’ve written about it twice. First I wrote about how to get the admin and other functions to work properly. Later, I wrote how to get the API to work properly when installed in a subdrectory.

But in the latest release, 1.7.9, the code has changed. This necessitates a slight change to the previous instructions.

My previous posts referenced changes to be made in the includes/functions.php and includes/functions-api.php files. The same files are needed here but instead of searching for YOURLS_SITE and replacing it with a substr() version, search for yourls_get_yourls_site() and use substr() on that.

Using the same example of my previous posts, let’s say that YOURLS_SITE is set to “http://example.com/subdir” (where “subdir” is the name of the directory where YOURLS is installed). Substitute the following code every time yourls_get_yourls_site() is mentioned in both files (except for the yourls_admin_url() and yourls_site_url() functions in includes/functions.php):

substr(yourls_get_yourls_site(), 0, 18);

The above is enough if you already had YOURLS set up this way in previous versions. But if you’re setting this up for the first time, be sure to add the following to the .htaccess file in the root:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9A-Za-z]+)/?$ /subdir/yourls-go.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+/?$ /subdir/yourls-infos.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+all/?$ /subdir/yourls-infos.php?id=$1&all=1 [L]

Tags:

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.