Support Sport Relief today

 

Click Here to Watch the FREE Blogging Video Tutorials

............Return to the Home Page

I Turned 404 into 200 With a Tiny Bit of php – Part 1

This entry is part 1 of 2 in the series I Turned 404 into 200 With a Tiny Bit of php
 

Please excuse the semi-cryptic title; but the whole issue was a rather large conundrum for me; so I do think it fitting:

I’ve just done a week of self-imposed intensive Linux study: Although it certainly and without doubt expanded my mind, it wasn’t actually necessary, as in “vital”: -

In this and the following article; I intend to relate how I surprised myself by solving what appeared to be a major problem on an Ubuntu dedicated server, by inserting just a single line of php into WordPress.

Here is the situation that I was faced with: -

I needed to move this blog onto a dedicated server, as it was hogging resources on the shared-platform server that it was currently on; and my hosting company have a policy of moving sites that did this onto a backroom scripting server that was virtually inaccessible to the net, as it was full of other sites that also hogged all the server’s resources, leaving none for the victim’s resource-hungry blog to use. They do this without warning ; and they tell you after they’ve done it.

Because the shared-platform server is shared between a number of websites belonging to any number of customers, there’s no way that I, as a user, could pre-empt this in advance. No server resource-indicator was available, and as I clearly stated; the hosts didn’t send an email saying “Your blog is using too many resources. Please see to it within 24 hours or we’ll stick it onto a backroom server…” – They just did it anyway, regardless, and any notification followed that.

The third time that this happened, a week before writing this blog post, I decided that I was going to rent a dedicated server: I had 8 active domains, 7 were hosted, and all on shared-platform servers. It was costing me a lot more to keep them each on a shared-platform server than it would do to put them all on single a dedicated server, and since only 3 of them were active, 2 noticeably so, it wouldn’t overload a single low-calibre server, at least for the time-being.

I asked to upgrade to a dedicated server, and one was set aside for me, and was online within 24 hours. Expecting things to be much the same on a dedicated server as on a shared-platform server, minus the resource issues, I moved this blog to the new dedicated server: I copied the database to the space I’d reserved for it on the new server using the mysqldump feature, following which I copied all the files from a backup of the shared-platform server and FTP’d them up to the new server in the domain-space that I’d pre-created for it.

Under normal circumstances that would have been that, and I’d have got straight up and running, and continued the blog from that point. What I didn’t notice straight away, until I had egg on my face because I’d just sent out a bulletin to my mailing list that the blog was back in full operation, was that every link on the welcome page resulted in a 404 when clicked. – Oh s—t!

What now? I phoned the web-hosting company: fasthosts.co.uk. The guy I spoke to told me that I’d forgotten to install a WordPress plugin, and suggested that I look in the WordPress plugin directory for it. I asked if he knew which one it was, or had a clue what it was called. He replied that WordPress was a third-party application that the support department don’t support, and therefore he was not allowed to tell me even if he knew.

Thanks for nothing. To cut a long story short I made so many calls to the support department over the last few days that I think I must have spoken to everyone who worked there at least once. I learned that there were 3 people there who were quite technically astute, and that 2 of them were very nice friendly types. The others were either distant and matter-of-fact, or as unhelpful as possible. All will remain nameless for the purposes of this article.

I developed a friendship of sorts with a couple of them, and we discussed the issue to some degree without breaking any company policies. One of them suggested that it could be that the database hadn’t connected with the files because I’d initially negligently forgotten to allocate the database to a particular domain when I created a reserved space for it in the system. After uploading all the files and the database again, this assumption proved to be incorrect.

Another one of them suggested that the reason why a lot of the “pretty” URLs that WP uses were resulting in a 404 was that the server’s mod_rewrite feature in Apache was switched off by default for security reasons. Once again it was against company policy to discuss this to any more helpful extent. On investigation I found that indeed mod_rewrite was off by default. I asked around as well as scanned Google and posted on this blog, asking for people to tell me ways to turn it on, and I used pretty much all of them, without result. (I notice that during my week of cyber-abstinence my viewers have mainly deserted this blog; but I suppose if there’s nothing much there to browse it might seem pointless trying to browse it.) I even ran a script to see the state of mod_rewrite; which told me it was now on, so seemingly my switch-on operations had worked.

I could have asked the host’s engineer to check it and do it himself if it wasn’t done properly; but at £60 + VAT per 1/2 hour, charged by the 1/2 hour, there was no way that I was going to be ripped off that way.

The result was…no change: I still got the 404s, even though I’d changed the URL structure to default in the permalinks section, which did give me less 404s to worry about it’s true. –Any 404s where there shouldn’t be 404s, nevertheless, is too many. – Worst of all the RSS feed still wasn’t working.

It appeared that the blog was dead. – I made a logical assumption that something somewhere had corrupted and that was that. It was at this point that I made another announcement that would leave me with major egg on my face: I announced to my mailing list and also to Facebook that the blog was dead, and that I’d get another newer domain set up in its place, and copy over as much content as I could get hold of that I felt was of any value.

I built shazzalive.com on the server; which immediately suffered from the same problem as that described above from the word go. Major problems!

I decided to see if there was a different solution to the problem available. Somehow I inadvertently stumbled across a blog article written in February 2008. (I’ll give credit + link & trackback in the follow-up article.) In it the blogger, who it seems knows php well, was saying that he’d had a similar problem, and that he’d used a line of php to solve the problems. Although English clearly wasn’t his first language; and his php notation was incomplete, it gave me ideas: This might be the solution that I was looking for.

First came the job of rebuilding the line so that it looked like actual php, as you’d expect to see it written in a WordPress php file: It did look like a piece of a php line (The structure of it indicated that.); but it seemed that it needed a beginning and an end. Since all I had to go on was what I saw, I enclosed it in the usual angled bracket used mathematically to mean “is less then”, followed by “?” and “php”, and ended it with “?” and the greater-than sign on the following line. It now looked like a proper php line.

The second task was to determine where in WordPress he’d put this line. He said that he’d put it in the “php application”, (Remember; English wasn’t his first language.) and further down he’d indicated that he’d placed it at the top. From the look of it, it just gave me the impression that it should go inside the header.php file; so that’s where I put it, at the very top.

‘Moment of truth: All the URLs appeared to be working as they should, even the “pretty” ones, and no 404 error from the server; but I was going to have to have better than that before I settled on it. – I went into permalinks and set the URL structure for the “prettiest” format I could: Date and time etc. – Now would I get results? YES! Everything worked; including the RSS feed! (I reset the URL format to the format that I’ve always used, in order that my URLs as listed and linked in search-engines synchronised, despite it not being the most SEO-friendly format.)

Target neutralised! (At last!)

So what was the line of code I used? Part 2 will reveal all; including a step-by-step guide to including the php in your own blog. :) Make sure you don’t miss Part Two; coming soon here on kkomp.com: – Taking you beyond the comfort zone.

 

Post to Twitter Post to Plurk Post to Digg Post to Facebook Post to Ping.fm

 

 

RSS feed

View Comments

No comments yet.

Sorry, the comment form is closed at this time.

 

 

Did you like this post? If so then why not join the Kkomp.com - Beyond community and get a free pdf report?

Use the mini-form below to enter a name + email address to receive your pdf report download location, as well as extra mailings:-

 

 

          

 

 

Please subscribe to my RSS feed. Click here.

- Confused about RSS? This short video should put your mind at rest: -
.flv (flash) format. (Real Player) - 9.185MB ~ OR ~ .wmv format.(Windows Media Player) - 11.330MB

 

Advertisment:

button

 

Advertisment:

Fire Your Computer Technician!

A computer technician spills the beans and makes available the knowledge he has charged clients hundreds in service fees for.

Computer Secrets Unleashed


CLICK HERE

 

The Lenovo ThinkPad T500

Thank you for visiting kkomp.com - Beyond. - Hardware + software + practical electronics + more. - Please drop by again.

 

* You loaded this webpage on 30-7-2010 5:33am UTC

* Your IP address is 38.107.191.99

 

Free PHP scripts from PHPJunkyard.com Free PHP scripts

 

 

Spam prevention powered by Akismet