I want to do what I assume is a relatively simple task, but I don’t know how to do it, because I am not smart enough. Here’s the deal:
I have copied the files from my old site, homepage.mac.com/wysz/, to my new domain, thewysz.com, in the /hotw/ subdirectory. HotW is Home of the Wysz, by the way, not Hot W.
I don’t update the files on the .Mac site, so I want anyone who visits one of those pages to know about TheWysz.com. I took care of this a while ago by just adding a link to my new homepage at the bottom of every page. It took about 30 seconds with TextWrangler. This isn’t the greatest user experience, because if the visitor wants to view the newer version of the page he or she landed on, he or she would have to know to replace homepage.mac.com/wysz/[path/filename] with thewysz.com/hotw/[path/filename].
What I’d really like is to get the file path of the page somehow written to the file itself. That way I could add a link directly to the new URL or even do a meta refresh. Unfortunately, due to technical limitations of .Mac, I’m pretty sure server-side redirection is not possible. I think what I’d want the action to be is a find/replace of <head> for the refresh, or </body> if I wanted to just add a link at the bottom.
So how can I do it? I have over 2,000 files to process, so it would have to be completely automated and not require me to open the files individually. I’m on a Mac, and not afraid to type into a Unix terminal window.
Thank you, smart people. And if you, my dear readers, cannot offer a solution, I will be very disappointed in you.
This is exactly why templating your pages with a server-side scripting language and generating them dynamically is a good idea. No need to search and replace over thousands of files.
You can always use javascript to get the current page URL, and then slice off any characters you want from the beginning. Unless I counted wrong, you would want to take off the first 28 in your case. So using the script below, you could append the current path of the page to wherever you wanted it to be (link on the bottom, meta refresh).
>SCRIPT LANGUAGE=”JavaScript”<
>!–
{
document.write(location.href.slice(28));
}
// –<
>/SCRIPT<
ahh crap…go ahead and make fun of me for getting those character entities reversed…forget it, you know what to do…here’s the important part:
document.write(location.href.slice(28));
yay for mike
Thanks, Mike. What do you think people would prefer? Redirect, or a link?
Nice JS Mike. That would definitely be right way to go, when server side redirects are not an option.
The best way I can think of doing that is, add at the top of every page:
Oops, looks like my HTML got converted. Didn’t see that coming. 🙂 . Attempt 2.
Nice JS Mike. That would definitely be right way to go, when server side redirects are not an option.
The best way I can think of doing that is, add at the top of every page:
I can’t remember how to add a delay on the top of my head, but I know it’s not a very difficult thing to do.
Thanks, Sasidhar, I went back and fixed your first one by escaping a few characters.
I give up.
My Comment
Wysz, wanna write me an post explaining ‘how to add html in comments’?. A Google search for that shows me ‘how to add comments to html’. 😐
Oh, thanks. A bunch of that didn’t even make it to the email WordPress sent me. Looks like a good solution; I’ll probably do that this weekend. I have to upload everything via WebDAV so it takes a while.
this tool looks like it will do the character escaping for you: http://www.reconn.us/component/option,com_wrapper/Itemid,62/
Thanks Mike. Looks like a handy tool.
Hey Mike,
Let me know if any of the above suggestions work for you. If it doesn’t, I can write you a short perl script (20 – 30 lines max) that will do all of this (recurse through and just throw in the link).
-mjp
Jack – That would be great if I could run it locally and insert a meta refresh (and static link) in the HTML so I don’t have to rely on JavaScript. Let me know if you come up with something.
Okay, finally I’ve gotten around to doing a JavaScript redirect. I had to modify the suggested code a bit. I’m sure I didn’t really need to set those two variables (you’ll see if you take a look at what I did), but it was easier than making sure I had all my parentheses and stuff in check on one long line.