.htaccess redirection using mod_rewrite

I make it a policy of mine that if three people in the same week ask me about something, that I should just make a blog post about it. This week’s apparent hot topic is HTTP redirection; there are tonnes of ways to do it and I’ve just been giving out a link about 301 redirects in various languages. Most people want to go with .htaccess method.

Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Please REPLACE domain.com and www.domain.com with your actual domain name.

The website’s a little out of date though; it no longer has to be a Linux server (did it ever have to be..?), so long as you have mod-rewrite enabled in your Apache conf file, you’ll be fine. Like the quote says, this just makes sure that anyone that comes to your website is using the www subdomain. (Sidenote, if you have  a choice of no sub-domain vs. “www.”, go without the sub-domain.) So, someone going to “neopets.com” will instantly (without them even seeing a page refresh) be taken to “www.neopets.com”.

That page doesn’t give much of an example of what all that code is doing though, so I’ll go through it here so that you can modify it better for your own use.

The “Options” line is an options directive, allowing you to set pretty much all of the options you can set in Apache conf files (so long as you have the right permissions; also, higher up directories override subdirectories). Here, we’re telling Apache that we want to follow system links (links to other directories, even though they’re no physical, like a shortcut). Your redirects most likely won’t fall apart if you don’t have that line.

The rewrite engine is where the awesome happens. The next line just turns it on.

The “rewritecond” is the evaluative part of the redirect. It checks to see if the URL that the user is looking at is the same as it’s argument. You can get the syntax for that evaluation from the rewrite engine’s man page, but essentially it’s just:

rewritecond %{variable_name} patterntocheckagainst

It uses a regex argument. If you don’t know regex, you’ll probably want to go and look at some tutorials first.

The [nc] at the end just makes the URL case insensitive. You can have multiple possible rewriteconds by using [or], and having another condition on the next line.

Last is the rewriterule, syntax here. Again though, it’s regex. It’s a useful skill for any one that codes in anyway, so you may as well learn it.

Again, there are flags, wrapped in square brackets. The [r=301] is telling the browser (and more importantly search engines) what type of redirect it’s doing; 301 is a permanent redirect. It’s just a HTTP status code, make sure you pick the right one. 307 is a temporary redirect.

If it’s still a bit over your head though, you could always contact me and get me to do it.

If you ask me, the week should start on Thursday.

Growing up on LiveJournal and Neopets (gosh, I can’t believe it’s been so many years since I’ve used those websites) I think it’s understandable for me to forget that the Internet is actually full of people. Sometimes I think that subconsciously I imagine all this content online to have just appeared from no where, or written by people on other continents who will always remain a stranger. Even some of the people I’m friends with on MSN that I’ve never met are dehumanised in my mind.

That’s why it’s refreshing to bump around the Internet and find people who not only seem to exist, but live pretty damn close to me. I found these strangers through total serendipity. I was looking at the Fizzpop event page for today (which I can’t go to – I wouldn’t be able to get back home), and then ended up at the Digital Brum site.

They’re listing web related events around Birmingham, some of which I’d love to go to, if only to give me something really interesting to do, maybe meet a few more interesting people. Then I found out about Digital Brum which lists a whole load of other events happening around Birmingham.

Ultimately I ended up at the Birmingham Social Media Cafe website, where they were listing past attendees. An entire list of people in interesting positions, most of them with links to their products and blogs. There are some people like Rob Day who’re 16 years old and have two projects that are looking really awesome in the pipe line. Kind of makes me feel like I’ve wasted my teenage years. This is totally the age of the teenage entrepreneur, and so I’m disappointed in myself for not doing anything amazing. Still though, it’s inspiring for me to do something now.

Found Calum Brannan’s blog too. He has a meeting table. A meeting table! It’s weird how small things like that really get me excited about eventually working for a company. Hopefully a small company. He’s working on Youmeo, which really looks interesting. I was thinking the other day how annoying it is to have both my Facebook and Twitter to update. (A few people who attended that event are working on Youmeo on second glance. I’d love to work on a team project…)

All in all, I’m mad hyped about eventually having a career. At the moment (well, especially at the moment, whilst university is finished till October) my work load isn’t that big. Heck, I sleep in till one o’clock most days just because I have nothing to do. It’d be really nice to get a job at a web start up or something. Places like arc90 who have amazing ideas in their lab (but they’re American).

I guess I could actually full time start freelance work; looking for new clients from nine to five, rather than taking on the clients that come to me (which is only a small number really). When I’m not looking (I’d probably get bored with eight hours of cold-emailing people from job boards), I should be developing my knowledge on general stuff. There still stuff about WordPress I’d be interested in poking around more with.

I’m going to make tomorrow busy.

There’s no need for the government to step in

I’d probably be the person my friends would think most likely to lobby for laws net neutrality, but they’d be wrong. Don’t get me wrong, I’m massively pro-net neutrality and think it’s vital for the continued growth of the Internet and innovation. What I don’t agree with is further legislation.

In England, our current state of play is that the government thinks everything is fine, despite BT capping and throttling. I agree with them. I don’t think that the government should step in and force private companies to follow their morals. The government has no say in how BT should be running their company.

But I’m paying for an 8Mb connection! That’s what I should get.

No, you’re not paying for an 8Mb connection, you’re paying for the service laid out in the terms and conditions you signed up for. Terms which you said you agreed to when you made the contract for your service. Those conditions openly say “we’re going to throttle your connection to 896Kbps for streaming videos”, and everything else Ars is complaining about. If you don’t like that, there’s plenty of competitors who offer different terms. Use them.

There are hidden terms like this all over England; buy one get one free (the cheapest product is the free one) — free calls between 7am and 7pm (if you start a call at 6pm, and then go past 7pm, you’ll be charged for the entire call) — 30% less fat! (30% smaller bag). It just enforces that it’s important to read the small print. That’s all the onus there is, and all that there should be on businesses.

Whilst I don’t think there should be harsher laws about how terms are written, I do think it’d be a good idea for businesses to voluntarily add a simpler version of their terms. Just to make their customers happier. I can’t seem to find it, but I once found a website who had the normal legal text – hard to understand by anyone that’s not a lawyer – but by the side they had simple explanations. In someone like digg’s case, by the side of…

By creating and posting Content to Digg, you warrant that you own all rights to the Content, agree that the Content will be dedicated to the public domain under the Creative Commons Public Domain Dedication, available at http://creativecommons.org/publicdomain/zero/1.0/ and that you will not object to the use of the Content by Digg in any context. To clarify, the above does not apply to the Content on external sites linked to by the original submission.

They could have “this just means that anything you give us is going to be put into the public domain, so anyone can do anything with it.” Digg’s ToS is actually pretty easy to read already, but other companies could really do with doing that too.

I don’t want to spend half an hour reading something before I can use a product!

That’s your choice, but the business has done everything they need to do in my opinion. You can’t complain when they suspend your account for doing something they don’t want, or when you’re hit with hidden charges. It’s your responsibility to read that stuff.

If the government can’t regulate, then who’s watching for consumer rights?

The consumers. If BT customer doesn’t like something they should leave BT, boycotting it. If enough customers are leaving (so it’s a big problem) BT will change. If you stick around with BT and put up with you, you’re sending the message that you’re okay with it.

That’s why I’m hopeful that if non-net neutrality comes into place, it’ll be fairly quickly kicked to the curb. There will always be some good guys in business. I’ve heard good things about Be. If there’s truly not anyone filling that need, then someone will pretty quickly notice it and set up a business there. (Hey, why not you?)

In sum, quit worrying about net neutrality, it’s here to stay. Government shouldn’t keep regulating businesses, let the customers do that. (You can almost feel Ayn Rand in the room, amirite?)

NoClassDefFoundError error, and a note on Bing

Playing with Java and for some reason I’m getting this error:

Exception in thread "main" java.lang.NoClassDefFoundError: AddingMachine (wrong
name: sum/AddingMachine)
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(Unknown Source)
 at java.security.SecureClassLoader.defineClass(Unknown Source)
 at java.net.URLClassLoader.defineClass(Unknown Source)
 at java.net.URLClassLoader.access$000(Unknown Source)
 at java.net.URLClassLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: AddingMachine.  Program will exit.

I decided to Google it, like I do when ever I get an error of any kind. Then I remembered bing, and thought this is an ideal moment to try it out.

Bing being new isn’t an excuse that they can use to defend it; Microsoft has has years experimenting with search and should know just about as much as Google now, but they’re still making school boy errors. For instance,  this forum post is listed second in the results.

Bing should know it’s a forum, it’s pretty obvious. Then by that it could deduce that the person starting the thread is asking a question, likely my question. But there are no replies, so it’s clear that no one has answered it. Giving me that link is completely pointless. Google learnt that lesson years ago.

Back to the Java problem, I tried doing java -classpath . AddingMachine rather than just java AddingMachine and I get the same error…

Fix’d: I just copy-pasted the source from the java notes page I’m looking at. And the problem lied in it have a package sum; line. Just remove it.

Edit for protip: This is an error you’re running into because of packages, used to make java source files easier to manage. You should definitely check out this tutorial on packages if you’re having problems; Java Package Tutorial.

It’s hard to see your point…

I’m leaving it a little late, but I wanna look through party policies, more specifically MEP policies. The people I have a choice of are listed for the West Midlands.

Is it wrong that I’ve mentally already ruled out Bushill-Matthews because he doesn’t have his own website? I guess it could show that he’s not exactly technically competent, and that’s really something that’s important for me to be expressed in Parliament especially at times when file sharing policy and law is being made. However, it looks like a Conservative policy to have all their MEPs on the same site, so I guess I can let them slide. Conservatives are the only people using @aol.com and @hotmail.co.uk addresses. Don’t they see the security implications of not hosting their own email servers?

Finding out what a person is standing for is working out to be really hard… Most of these pages are like CVs, or just blogs of political news, recounting the news too, not even offering their view on the matter. Assuming though that every single one of their views is the same as the party they stand for, I guess I’ll look around the party’s websites.

But they’re not much help either. Take immigration, a blatant issue at the moment, one of the hot ones that everyone needs an opinion on. Labour’s immigration page lists various facts over what’s happened whilst they’re in power, but I really fail to see why they’ve listed a few.

In 2007, we removed an immigration offender on average, every 8 minutes.

It’s nice to know that there are that many in the country. How did they get by you? We’re an island, it’s not like people can just flee across the border. And if immigrants are up to swimming an ocean to get in, I think maybe we should let them in on merit.

Other than saying they want to give ID cards to immigrants (wasn’t that happening to everyone anyway?), and increasing the number of people who work at these borders (which everyone wants to do), I don’t think they’ve mentioned anything controversial to differentiate themselves.

Oh, I suppose when you look at the Conservative page side by side with the Labour one, you see where differences are. Labour don’t have an interest in setting a limit to the number of immigrants allowed per year, which I can understand. If we have a system where we only allow people in that we need, why set a limit? Once all positions have been filled, just stop letting people in. Tory’s do want an arbitrary limit though, the point there being that too many slip through, and if we just say no to them before even letting them speak we’ll have lowered their burden on our public services. The Government has nothing to gain by allowing millions of people to come into the country, if anything it’d just make their jobs harder. I don’t see the point in setting a limit. I think we should just let in people we need, but be very strict about the guidelines for “who we need”. If there’s not a job position already available for them, leave that job for someone that’s already settled here. I’m a little bit shocked by it myself, but I guess that’s a point to Labour…

There’s these border patrol people too; Tory’s want them to be apart of the police, whilst Labour want them to have “police like powers”. Semantics really. Just something to argue about. The police are already over stretched as it is, why give them another job which requires them to get rather niche training. Have a specialist team to do that. Increases jobs and they’ll be more focused. Labour win.

Both of those points aren’t relevant to this election though, European Parliament doesn’t have the power (or the need) to touch either of those things. But it really shows that I have no other information to go on, other than the party policies. I can’t find much about what the hopeful MEPs want.

I can’t find anything the Lib Dems have said about immigration… What? I can’t say I’m surprised they don’t seem to have written up, public policies for most things. I’m not going to bother looking at UKIP. I’d never vote for a less globalised world.

Lib Dem Liz Lynne’s site has a few sections on her website listing a few things; Iraq, business, various campaigns. That’s exactly what I want to be reading! I clicked through to the business one. The links on there link to search results… completely pointless. Meh, I had such high hopes, Liz! Looks like she’s about giving business more power over themselves, and deregulating some things though.

Liz was [...] on the Vibrations Directive and the Noise Directive, negotiating a number of key amendments to make them less onerous on businesses.

I like this pro-business stance. I’m really all for businesses creating their own morals, even to the extent of Ayn Rand’s ideologies, and so they’re the ones that get punished for them if there’s a mistake.

All in all though, the Internet doesn’t really tell you enough to decided on who to vote with. I’m going to keep researching, but unless something changes my mind, I think it’ll be Lib Dems for me, despite it being a wasted vote here (but hey, maybe enough people will think like me).

After weeks of aimless doing nothing…

I plan on being busy tomorrow. Today wasn’t much of a productive feat either, despite me being back home. Apparently a change of scenery hasn’t inspired me to work. It looks like my main village is about to be nobled though, so I guess I won’t be playing Tribal Wars for much longer…

Tomorrow, I’m gonna head to dad’s around five o’clock, because I can get a lift at that time. I want to fix my bike up (it’s been out back for  a while now, I wouldn’t be surprised if it’s rusted beyond repair but I want to try. It’ll give me something relatively cheap to work on. Then, I think it’d be cool to just ride for a while. Mostly to increase my fitness, to be honest.

Then, ride back to mum’s – since I don’t have a bed back at dad’s house yet (the spare room got filled with junk as soon as I moved away to university). Or, better yet, I wanna check out the library. I’m not sure if they have wireless there but if they do it’d be rocking. If not, no problem I can do computer science theory stuff I need to do anyway – I’m sure they have books.

Back to using WordPress.com

I’ve decided to switch back to using WordPress.com for a while, and domain forwarding to it. So, all the links and stuff should still work. Only problem in the switch over was that my tags and categories got messed up so I’ll have to spend an hour or two just going through all of them to fix them up.

For those that don’t know, wordpress.org is the open source website, where you can run the software yourself. WordPress.com is a commercial arm (they have to make money somehow) where you pay for certain services, and have a lot less freedom.

I decided to “downgrade” because there’s blatantly something wrong with my server. I don’t think it’s anything on my part, more on the part of my VPS providers (since their websites were down too). After weeks of slow loading, and database crashes, I’ve decided to just go self hosted for  a while.

The blog should be way faster now, and always work. Downside is it cost me £7 to have the domain forwarded. And I can no longer installed plugins, or themes. I can only use the ones WordPress.com offers. I can’t show ads the way I used to (only to first time visitors, on certain single pages/posts). I wasn’t making much money off them anyway, so it’s not a big loss. And I’m a little worried with putting my information in someone else’s business. I’m really hoping I’m not surrendering any copyrights to this data by putting it here (I’ve not read up enough yet).

Other than it being managed by someone else, I don’t see any up side to WP.com. I’ll be switching out as soon as I get a better server.

Could be the DNS playing catch up still, but it doesn’t look like I can use my OpenID any more…