Skip to content
Easily add 302 redirects to an .htaccess with duplicate checker
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Easily add 302 redirects to an .htaccess with duplicate checker

See the script for details

It is thoroughly commented throughout.

You will need to tell the script which app you are using to sync your local .htaccess with the server and you will need to tell it what the domain name is for the URLs that you want to create.

These can both be set by editing these lines in the file:

# This could also be Dropbox or something else
SYNC_APP="BitTorrent Sync"

# this is the domain to use with the short URLs

Usage: Two Args

Ideally you will give the two arguments:

  1. the "slug" that you want to use with your domain name

  2. the URL that you want the slug to redirect to.

Example: Foo http://some.tld/path/to/whatever/you/want

Ok, but that's a theoretical. Here’s an actual example: say I want “CleanDesktop” to redirect to “”. Here’s what I would do: CleanDesktop

Note that it doesn’t matter which comes first, the URL or the slug, so I could have also done this: CleanDesktop

and it would have given me the same result.

What does

First, the script checks the .htaccess file to make sure that you aren’t trying to re-use a slug, because that would be bad.

Secondly, it will add the appropriate redirection line to .htaccess. In this case it would be

redirect 302 /CleanDesktop

If the slug that you have chosen is not all lowercase, then will also add a lowercase version to the .htaccess. So, using this example again, it would also add:

redirect 302 /cleandesktop

I prefer to use CamelCase when I make short URLs, but if I tell someone the URL, I don’t want them to have to worry about capitalization. checks .htaccess for both the original and lowercase-d versions of the slug, and if either exist, it will refuse to add the new slug, and tell you why.

Usage: One Arg

You do not have to give two arguments. For example, you could just tell it the URL that you have, and it will prompt you for the slug. For example, if I had said

then it would ask:

What slug do you want to use for ''?

Or you could give it the slug and it will ask for the URL.

(It does this by checking the first 4 letters of the input. If it is “http” then it assumes that is the URL. If it starts with something else, it assumes that is the slug.)

Usage: Other

If you give something other than 1 or 2 arguments (for example: 0 or 5 or 237), it will not try to guess what you mean, and will prompt you for both the URL and the slug.

You can’t perform that action at this time.