Welcome to WebmasterWorld Guest from 188.8.131.52
Forum Moderators: bakedjake
I made a website with about 100 pages(give or take 10) and it's actually a sub site for a department in a large company. So I had some guidelines to follow. Basically I had a header to repeat on every page. Now I got the preleminary header set up from the companies Web Master and it had all the links and everything set up. Now, for some strange reason the WM changed a link from www.mysite.com/page.html to www.mysite.com/about/page.html
(these are examples names, but same situation). Is there a way I could write a script to go through the entire web folder of my account on the unix system and change ANY occurrence of www.mysite.com/page.html to the correct one? This is spread across 3 levels of directories and about 100 files total. There is one "root"(not root of the system) directory which I can start from and everything in is my own, and pages that I need to change.
I would assume I could do something like this from my limited experience of Unix O/S's but I"m not sure how to go about it.
Any starters?( I don't have root log in... but I could hack *cough cough* get it, if need be).
This is just to get you started, in any case your syntax will probably be different because I use the tcsh rather than bash.
As someone posted in response to a vaguely similar query, if you are doing things to files in a hierarchy find is your friend.
A first cut (remember, your syntax will vary) is along the lines of:
foreach $file ( `find starting_directory -name "*.html" -print`)
cp $file $file.sav
sed 's/bad url/good url/' $file.sav > $file
Just to start you experimenting, I have not tested this and am in no way responsible for anything should you be unwise enough to implement this ;)
Remember to clean up the file.sav's after you are finished and have checked that everything is OK, another find will happily do it for you.
Now, for some strange reason the WM changed a link from www.mysite.com/page.html to www.mysite.com/about/page.html
one quick way to fix it is add a symbolic link between /page.html and /about/page.html.
# cd [document root]
# mkdir about
# cd about
# ln -s ../page.html page.html