Redirecting Question

Note: This is a techie question, all those not interested, look away now.

(and no, I’m not doing very well at the whole ‘staying away from the blog to be productive thing…)

[update]SORTED!!!
That nice man wot writes Hydragenic came through for me (apparently he would ‘not be defeated’, he cracked it second time round).

I’ve added the following line to my .htaccess file on the gordonmclean.co.uk domain:
RedirectMatch 301 /index.php/(.*) http://www.onemanblogs.co.uk/index.php/$1

And now when you click this link (which points at the gordonmclean.co.uk domain) you’ll be properly redirected back to this domain (onemanblogs.co.uk).
[/update]

I received an email the other day. It was a nice email, the very kind I’d hoped my 404 page would generate.

The problem is a simple one. I moved domains a while ago, so some of the links that still exist point to my old blog URL (which is still live but is no longer a blog).

Following one of those links (from Lifehacker.com I think) will take you to this URL. Which is currently displaying a 404 error message.

To get to the correct page, all you need to do is edit the URL, replacing “gordonmclean” with “onemanblogs”. Simple.

So why the hell can’t I figure out how to write the appropriate .htaccess commands to get it to do that automatically.

I don’t want to redirect everything, only anything that has “/index.php…..” in the URL. Shouldn’t be THAT hard, right?

Well I’m stuck. So, dearest technical interweb friends, help!!

Written By

Long time blogger, Father of Jack, geek of many things, random photographer and writer of nonsense.

Doing my best to find a balance.

More From Author

A clock showing the split of time between events

The in-between

A generated image of many app icons in a colourful display

Not yet sherlocked

Painting of the american flag on concrete, a large crack splits the flag in two

Fuck Trump

You May Also Like

An image representing writing and blogging

Where will we go?

Photo of me and quote from the article

Some more about me

Six Thousand

5 comments

If you’re struggling to get .htaccess to cooperate, maybe you could simplify things. Why not use a PHP document as the 404 page, and then put the logic behind the redirection in the PHP. Maybe even a cunning regular expression. Make sense? I’m not so great at expressing myself this early in the day.

I don’t have an easy way of testing this myself, but if it was me this is what I’d be trying first:

RewriteCond %{HTTP_HOST} ^(www.)?gordonmclean.co.uk [NC]
RewriteRule ^index.php$ http://www.onemanblogs.co.uk/$1.php [R=301,L]

Bugger, WordPress has sanitised my input. It’s all correct except that the “1.php” in the second line should have a dollar symbol immediately preceding it (i.e. after the forward-slash).

Let me know if it works!

The inelegant sledgehammer solution (if all else fails) would be to put some javascript in the 404 page and redirect using that by substituting the domain if it spots a wrong ‘un.

I know. Eww.

Cheers guys, good ideas all.

And I’m flattered that you think I’d know how to do it in PHP or Javascript! πŸ˜‰

Can’t do anything with this until this evening or, more likely, Sunday…

Comments are closed.