Redirect a bunch of URL to a single URL in Apache

I recently faced a situation wherein I have to permanently redirect a list of URLs to a single URL. I’m used to doing it for 1 to 1 redirects(1 url to another) but this is the first time I did it for a lot of URL.

Example:

http://www.example.com/oldschool/index.php?i=1

http://www.example.com/oldschool/index.cfm?i=55

http://www.example.com/oldschool/SchoolOfRock.html

http://www.example.com/oldschool/School-of-Knocks.htm

will need to be redirected to:

http://www.example.com/university

The solution? Use the RedirectMatch directive in Apache
It’s so easy to use. Use the syntax:

RedirectMatch [status] regex URL

where status is 301(permanent redirect) or if not used will 302(temporary redirect) which can be used in you Apache’s server config, virtual host, directory or .htaccess context.

In the above example, the exact RedirectMatch is:

RedirectMatch 301 ^/oldschool/(.*) http://www.example.com/university

Posted in apache-httpd | Tagged , , | View Comments

Microsoft embraces AMQP open middleware standard

Excerpt from InternOpNews.com

“What is AMQP, and why should anybody care whether Microsoft adopts it? Well, I’ve already blogged at considerable length about where AMQP comes from and how it works, so I won’t rehash all that here. Suffice it is to say that AMQP is to high-value, reliable business messaging what SMTP is to e-mail. The proprietary message oriented middleware (MOM) products on the market today like IBM’s MQ or Tibco’s Rendezvous fulfill the same function as AMQP. But they operate exclusively in single-vendor fashion and utterly fail to interoperate with each other. They are also – perhaps not by coincidence – burdensomely expensive. As a result their use is mostly limited to wealthy organizations such as Wall Street banks (at least the ones who are still in business) that need to exchange huge volumes of business messages very reliably and very quickly. But AMQP’s supporters feel the market for such reliable messaging could be much larger if a less expensive and truly open solution became available”

Read more on InternOpNews.com

Posted in microsoft, open-source | Tagged , | View Comments

Twitter from Command Line

You know about twitter right? If you love using it, you may be pleased that you can do it in several ways including the command line. Yes, from the CLI.

Just follow this simple steps from Dave Taylor’s post in LinuxJournal.com

Happy Twittering!

Posted in Uncategorized | View Comments

Your work shift is up so DON’T touch the code!

I’m not advocating going home seconds after your work shift ends. Rather, I just want to rehash the proven rule that you should never touch the code if you can help it because the probability that it will break is so high when you’re in the “go to bed” mood. Just do the changes the following work day when you’re sure to have a fresh mind.

Various examples can be cited but the experience I had several days ago is a concrete one. To give you a background, I work in an internet-based company — an experiencial travel directory with the official designation as an SEO. Our current websites are edited “real time” in our development server and then transferred to production server via ftp. Now, seconds before my work shift ended, I suddenly realized that I can still insert a major keyword in our main search pages. I got so excited coz months ago I was resigned into the idea that there’s no more room for additional key phrases in the main search page.

Not wanting to loose the excitement, I fired up the terminal application and connected to production server via ssh. I was so confident that nothing will go wrong coz I will simply add the major keyword to the search page and I know very well that the part I’m about to edit is a static text and hence a no brainer. The first few directories’ search pages I edited went well as expected. It was 2:30 AM and I was already planning to defer doing the changes for the following day. However, I decided to edit one more before I can call it a day. I made the edit, flushed the web caching system, then refreshed the browser for one last look….BANG! The search page has an error. I panicked a bit knowing that this directory has the greatest traffic in all our websites. I tried finding the error stated but I can’t seem to find it.

For about 20 minutes, the search page was broken. I tried recalling and validating what I did but still what I can remember is that I simply added the keyword phrase so my brain was insisting that it’s not the source of the error. Programmers were no longer around and besides, it was already 3:00 AM so I don’t want to disrupt their rest. Left with no choice, I had to fix it myself…a punishment for breaking the “rule”. Good thing the other pages where not affected, including the“searchtext”1.

With the searchtext still up, I had to redirect the main search page to it so that I could fix the page without discouraging tens of thousands of visitors that’s currently using the directory. Also, the redirect has to be “temporary” so as not to affect the crawling of the page by Google and other search engines. I preferred doing the redirect through it’s apache virtual host configuration (refer to Figure 1) but I could have done it via the coldfusion language(refer to Figure 2):

Figure 1. The apache vhost configuration

Figure 1. The apache vhost configuration

Figure 2. Equivalent configuration

Figure 2. Equivalent configuration

With the main search page redirected to the searchtext, I now had the time to fix the code. Not all visitors may like the way the current search page is formatted but it’s better than having a search page and be greeted with error.

notes:
1 a page that is somewhat like our search page but lists all the options a user can choose with the dropdown menus in the searh page. This is mainly for search engine crawlers but is still usable by humans.

Posted in Uncategorized | View Comments

Quick Hack: ssh connection over a slow internet

Ever experienced being connected to a remote server via ssh and your terminal freezed due to inactivity? That happened to me several times and I will be a liar if I say I liked it.

Fortunately, I found out about “top”, a *nix command that it intended to show the top processes in the machine you’re logged on to. This same command is what I use as a quick fix/hack to the terminal freeze problem I have.

Freezes happen because connection to the remote server has been idle for some time and the remote server thinks you are not anymore interested in the current session that’s why it decided to disconnect you…hence the freeze. To let the remote machine know that “I will be back please hold on”, just use “top”.

I still experienced some instances that my session was disconnected even with “top”(I think 1/100) but mostly, this short hack worked.

Try it…

NOTE: This is a repost of my old blogger blog dated Sept 14, 2008

Posted in Uncategorized | View Comments

Smartbro experience…including making it work for Ubuntu Linux!

In my hometown(Alangalang, Leyte), internet is not yet that widespread. We do have some internet cafes but it’s situated in the poblaction. I live in a barangay far from the poblacion and telcos says that as of the moment, they can’t yet service our barangay although a phone line is already possible. Then I heard of SmartBro. But then again, they would tell me it’s not yet offered for Alangalang residents. Fortunately, the SmartBro Prepaid version came shortly so I didn’t think twice in getting one.

The downside of getting the prepaid was that it has a very slow internet connection…even slower than a dial-up line(imagine a connection speed of mostly 25% of 64kbps!). But I guess that was the very reason of Smart for not selling to me yet as they know I will only be frustrated with the connection speed.

Smart signal is not a problem here as we could get full bars. With the Smartbro prepaid kit, I could get 3 bars at most but internet speed is not that good yet(as I just mentioned). I admit that I got frustrated but I still understand Smart as it’s not yet economical for them to allocate a larger bandwidth to an area that seldom has SmartBro. The only thing that I think Smart should need to improve on is the consistency of internet connectivity. I experience once a week that I can’t browse websites, not even Google using its ip address(to bypass DNS) and image loading in my browser turned-off(which is not a factor as the only image in its homepage is its logo). You can’t say that I don’t have load as I’m sure it’s not empty as I just reloaded it. Anyway, I hope Smart will improve in this aspect.

Enough of the introduction we’ll go back to the main topic: Smarbro working in Ubuntu Linux(Hardy Heron 8.04). This is nothing new actually. Another IT Geek(Arpee Ong) has posted this in his own blogbut there are comments that say’s they can’t make it work. His distro was Fedora but I tell you, I never made any changes to his instructions:
1. Created a udev definition for the zte mf622 hsdpa modem
2. Made a smarbro.conf configuration file
3. Run the config with wvdial (used “sudo” of course as wvdial is owned by root).

Another thing that I always liked doing is add some DNS in my /etc/resolv.conf, even if Smarbro provides their own, and I use OpenDNS for this purpose (208.67.222.222 and 208.67.220.220) since it sometimes resolves domain name to ip faster aside from the fact that porn/phising and other violent side of the internet is mostly filtered.

Lastly, I used Squid as my proxy. Install it via apt-get or Synaptic Package Manager. Give it a “visible_hostname” and put localhost:3128 in your browser and you’re ready to go. Browsing speed may not be immediately felt but as squid gathers more data, it will significantly help specially in your commonly browsed websites.

Posted in mobile broadband internet | Tagged , | View Comments

Nice Hack: Spamless Misdirected Corporate Email with Gmail

In the online world, misdirected/incorrectly spelled email happens. Yes misdirected emails just bounce back to the sender but that’s not a nice way to introduce your company to a new client.

Figure 1: (usual email configurations)

Figure 1: (usual email configurations)

Introducing catch-all. A Catch-all for email, according to Wikipedia usually refers to a mailbox on a domain that will “catch all” of the email addressed to it, so any email address at the domain that doesn’t belong to another mailbox will end up in this default mailbox.

Figure 2: (with catch-all,ideal situation)

Figure 2: (with catch-all,ideal situation)

Unfortunately, email spammers had come into the picture, trying all possible email address that your company could possibly have.

Figure 3: (with catch-all,ideal situation + spam)

Figure 3: (with catch-all,ideal situation + spam)

Now, you are to solve yet another problem: spam in misdirected email. Yes, you can draw from your experience and fight spam with every available means. But for me, I’d rather spend my time doing more important things than fight spam with all my might as it’s draining.

Here comes Google’s gmail. In my own experience, gmail has a more superior spam filtering functionality. I seldom have false positives. It has also an auto-forward option. That’s it: use gmail as your spam filtering solution and have it forward to you non-spam emails!

Figure 4: (with catch-all,google as spam filter)

Figure 4: (with catch-all,google as spam filter)

IMPORTANT NOTE:
While you are saved from managing spam and misdirected emails, you still need to weigh the pros and the cons in implementing the solution I propose above. Monitor the:

  • volume of emails that’s being redirected per day by your server to gmail, and
  • the number of legitimate emails that are actually received

as this is potentially bandwidth intensive. Try assessing if it’s worth saving misdirected emails. If maybe for two months you get 60-95% spam, you may just want to send those nonsense and misdirected emails to trash.

Also, don’t forget to ask permission from your bosses. They may not like the idea of sending your mails to Google, even those misdirected onces, for privacy reasons. Otherwise, you risk losing your job. You had been warned.

ACKNOWLEDGEMENT: This cool idea came from reading the post of ex-Yahoo and now Craigslist’s Jeremy Zawodny Using Gmail as My Spam Filter.

Posted in Uncategorized | View Comments