Posts Tagged ‘tips’

Using mod_rewrite to tidy up your links

Wednesday, March 26th, 2008


First of all, let me start by confessing that I’m not an expert in .htaccess modification. This is something I’ve learnt and I will guarantee that there will thousands of developers who know this topic like the back of their hand. Therefore this little tutorial is for those guys who may have been searching for simply ages for an answer that doesn’t seem to be out there. So please, if you’re an experienced programmer, please do me the liberty of leaving out all the usual flaming stuff that can be found on the likes of YouTube. Instead, please take the liberty of contacting me directly. With that said, let’s move on.

Well finally after a good few days searching solid for how to do it, I’ve done it. What am I talking about? Well, what seems like a basic PHP design tactic these days is tidying up your user’s address bar by using mod_rewrite on Apache. Not only that, but it also makes site design, as well as link management and organisation much, much easier.

I’ll give you an example, if you don’t know what I’m on about. Have you ever been to a site and noticed that in the address bar you see a link that resembles http://acmeinc.com/products or http://someblog.com/archives? The main thing to notice here is that usually people are used to http://acmeinc.com/products.html or http://someblog.com/archives.php - however this isn’t happening in this mod_rewrite technique. It looks much tidier, and makes maintaining the site a lot easier.

What’s going on under the bonnet?

First I need to explain exactly what is happening behind the scenes for those who don’t know. Apache, the server technology of a site, is receiving requests for web addresses, as you’d expect. If a user navigates to http://someblog.com, Apache will automatically look for the default page (usually something along the lines of index.html index.php), and dish it back out to the user. Let’s take a practical example. Consider Facebook - which dishes you out http://www.facebook.com/home.php. All good, but it’s ugly (at least by modern web standards).

Now with this little technique which you’re about to learn, things change. Mod_rewrite modifies the requests by “rewriting” the request that Apache receives from a user’s browser. The mod_rewrite rule I use appends “index.php” to a request if what’s requested isn’t found. Now you know what’s happening behind the scenes, let’s move onto how you can apply this to the structure of the site.



Applying this to a site

Ok, so what we discussed above seems very pointless at first, and usually people struggle to think how they can apply this to benefit their site. However, Wordpress is a good example of how people use it to help them. The technique I use is organising pages into folders that resemble what you would usually use as page names. Considering my site, I have several main sections. Let’s take my portfolio as an example. Usually, you may decide to use “portfolio.php”, and include this in your navigation however in my case things aren’t working this way. I actually have a folder called portfolio in the root of my server, and within that folder, an “index.php” file containing all the juicy content you would originally expect in the “portfolio.php” file.

Can you seen what happens here? So all my links will point simply to “/portfolio” (yes really, view my source) instead of “/portfolio.php”, which means Apache will get a request for http://www.george-edwards.co.uk/portfolio and deal with it by appending “index.php” onto the end.

You should now start to see things taking shape. This theory doesn’t work too greatly with a WordPress driven site (I find the file structure of WordPress pretty messy), but if you use it for developing your own site, you’re going to have a very tidy looking site structure which makes development in a text editor surprisingly simple.

Here’s an example. Consider you’re making a simple site for “Apache Software Ltd.”. Apache (like the name?) may want a typical four page setup - Products, Contact, About and News. Nothing unusual here. But let’s think about the directory structure (click the picture and look at our example in motion):

Post figure 1

Here you can see it in action. Your navigation would be very simple in this case. You may use a PHP include to grab navigation elements from the header.php file in the include folder. But the case remains the same - your links would all be along the line of “/products”, “/contact”, “/about” and “/news”. The same effect happens in the address bar. Your user would be looking at “http://apachesoftware.com/products” and they would never see the ugly “index.php” on the end. Imagine just how simple it is to manage, having everything in folders like that!

Modifying .htaccess to add the rewrite rule

One thing is left. We need to re-do the htaccess file. Simply add the following to the end of the file and restart your Apache service:


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Enjoy. Any thoughts? Let me know via the comment feature.

I’m a Veteran - and here’s my tips for success

Sunday, March 16th, 2008

I finally did it after a few sleepless nights and annoying points - I completed Call of Duty 4 on Veteran. It’s hard, and very tedious in places. It is also annoying - there are a few very obvious bugs that should be addressed in the game which obviously haven’t. The most obvious of these being the “unlimited respawn” issue. But oh well, it doesn’t stop it from being probably the most influential game of 2007.

But onto the campaign. If you’ve tried it on veteran you’ll know the problems and the bits you find tough. For me, I got stuck in several places: on Shock And Awe, One Shot One Kill, Hunted and No Fighting In The War Room. If you haven’t played the game, you’ll have no idea what I’m talking about. But here’s some tips for you if you’re struggling - because I can pretty much guarantee you will be stuck at the same places.

Shock And Awe
I got stuck on the bit where you need to jump out of the side of the building by the cargo containers, and you have a standoff with a few nasties on the roof of the building to your right and in the windows. There are also more dead ahead by the gap in the fence, past the pile of wood. Here’s my tips: jump straight out (there’s no point shooting from inside the building because once you are out of the building, you cross the invisible “respawn trigger” and the enemies start coming) and seek cover behind the fence underneath you. Start on the left hand side. Show only a very small part of you (because you’ll get murked if you stand there like a numpty), and pick off the guys that appear on the roof of the building. Eventually they’ll stop, so stand further back and pick off the guys in the windows. A lot will come this way. Keep at it, then eventually sprint to the right hand side of cover, and pick off the RPG guy that keeps respawning on the roof in the far left. Eventually, the numbers that spawn will go down. Now here’s the tricky part - the only way you will do this is by clearing the house on the right. So get some cover behind that cargo container, flash the bottom floor of the house, storm up to the door and before going in, slot the guy stood to the left of the door that always seems to get you. Clear the downstairs of the house, sneak upstairs and immediately scope before you get to the door (or flash the room), and clear the two or three guys in here. You might need to pre-shoot. Once you’ve done this, you’ll have a checkpoint, and you can move on. Oh - don’t forget the piece of intel/laptop hidden in the closet.

One Shot One Kill
Ah now you’re with the notorious Captain MacMillan, you’ve blew the guys arm off, you’ve ran for your life to the playground with the ferris wheel, and now you’re waiting for extraction. This part is absolutely insanely difficult, and no doubt it will piss you off beyond recognition. A couple of things to note here. As far as I know, if you stay at the back next to the Captain, you’ll just get annihilated time and time again. The enemies come from too many directions and it’s near impossible. The best way to do it is by seeking cover. Remember to lay all your claymores before you put the captain down by the ferris wheel, because he’ll give you a load more C4 and Claymores to use (so you get more…a bug in the game). The best place to seek cover is by the bumper cars. Run round there and hide behind the fence, so you are looking towards the ferris wheel. Have the Dragunov and the AK, and snipe the guys as they come down the chopper. Eventually you’ll be outnumbered and they’ll come up to your little hideout, and try crossing the dodgems - then just fire in bursts with the AK. Keep at it, you’ll get it, and the chopper will eventually arrive.

Hunted
Now you’re back as Soap with the 22nd SAS, and you have to escape a farm and get to the chopper in something like 3 minutes. This was tough and took me 2 days to get round - and I nearly through the Xbox out of the window. Best thing to do - use three airstrikes and kill the waves as they approach across the field whilst hiding in the barn at the back. Collect the Dragunov and the 249 or RPD and snipe any enemy as appropriate. After a while it goes quiet, so sprint down the middle of the field and approach a gap in the hedgerow on your right. Go through there, run through the fence and to the right of the house. You’ll see a road here, and as soon as you cross it, enemies will spawn from the house on your left - so naturally call an airstrike on the house, then SPRINT across the road and prone by the low concrete wall, facing down the hill towards the chopper. Don’t go round the corner because you’ll get mullered. By now, Gaz and the rest of your squad will be approaching the house where they spawn, so once you can hear them, crawl round the corner and towards the house. Don’t poke your head up too much as you’ll get a bullet in it. The aim here is to get into the house, alive. Once you’re in there (a lot of luck and sprinting is involved), run downstairs and be on guard as some guys like to wait out of the front of the house for you. Now might be a good time to call an airstrike on the far right of the hill from where you are, as that seems to be a spawn point. Now the next point is a lot of luck involved and for me became an adrenalin filled rush. Basically, run like hell from the house and down the dirt track you see in front of you, and down the hill. Don’t stop sprinting, you’ll eventually get it (you won’t need to shoot anyone) and you’ll reach a small fence to climb over near the chopper. Jump over it, and you’ll hit a check point. Then get in the chopper and grin with satisfaction!

No Fighting In The War Room
Welcome to the Russian missile site. Here you should start off being told by command that you have “9 minutes before the missiles reach the Eastern seaboard”. The key here is being very very very quick and very agressive. Immediately sprint to the right out of the door and you’ll see a corridor, with two initial guys coming out of a door. Kill them, run to the right, and kill these two. Ideally, you need to clear the kitchen area and reach the “red light tunnel” by about 7:45 on the clock if I remember correctly, and then you’ll get a checkpoint. The thing here is that the game doesn’t want you get stuck in an endless checkpoint loop by reaching a checkpoint without enough time to enter the abort codes - so the checkpoints are timed. Basically, be as quick as you can and you’ll get a checkpoint. There are a few checkpoints to get - one is in the kitchen at the entrance to the red tunnel. Second is on the stairway with the big wall carving, and the third is where Gaz asks what the bloody hell is happening and Price replies “they’ve started a bloody countdown!”. Straight after the third checkpoint I got pissed off with the tunnel, and the guys with the shotguns. Tip, go prone at the bit where you get picked off by the guys at the small tunnels directly opposite each other. If you edge round slowly until you see a body part, put a few rounds in them and they’ll drop. Rinse and repeat with any part you find tough and you’ll get it - as there isn’t any other way you’ll defeat this bit on Veteran because the enemy just knows where you’ll be and are robotic with their reactions, aim and timing.

Good luck - and remember the checkpoint problem on the final part - be quick! Oh, and you’ll get on much better if you follow a few videos that I used for help. Pop over to http://nextgenwalkthroughs.com for some expert help.

Now it’s on to Mile High Club…urgh, this will take ages!