.htaccesshttp-redirectyourls

Protect YOURLS with htaccess


I have a normal YOURLS installation and it is working fine. But I want to deny access to folders and files, redirecting all the traffic, except my IP, to domain root without losing the ability to do the normal redirection.

Something like:

doma.in/admin (which is the admin folder) redirects to doma.in

doma.in/admin/index.php redirects to doma.in

doma.in/J0f2k (which is some random shorten URL) redirects to whatever URL it is associated

Basically I don't want people seeing the login page or any file, but I don't want to password protect it. Simply redirect to domain root.

I have these rules:

RewriteCond %{REMOTE_ADDR} !^192\.168
RewriteCond %{REQUEST_URI} !/yourls-loader\.php$ #needed to do the redirection
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* http://doma.in/ [R=301,L]

But it is not working. Anyone can access the folders.


Solution

  • I ended up putting a htaccess file in each folder, redirecting all IPs but mine to domain root. They are just 7 folders, so it was not a big deal. And YOURLS still working fine.