LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Changing websites -- how to change all those URLS in all those pages? Sed? (https://www.linuxquestions.org/questions/linux-server-73/changing-websites-how-to-change-all-those-urls-in-all-those-pages-sed-919265/)

SharpyWarpy 12-17-2011 07:14 PM

Changing websites -- how to change all those URLS in all those pages? Sed?
 
Okay first off a confession. I don't run a server. But I figure I'm most likely to get a good answer in this forum. What I'm thinking about doing is changing to another ISP with DSL. When I copy all my current website files to the new ISP server I'll of course need to have the links changed to the new server. I'm thinking some of you "sed" gurus might have just the script I need to do that easily before I put them on the new server. Am I right? I'm not being lazy here, I know I could read the sed manual and finally get a good script for doing that. But when would I ever use it again? I would like to benefit from the experience of someone who has done this often -- that's why I think I'm in the right place. :) Thanks in advance.

fukawi1 12-17-2011 07:32 PM

What links do you need to change?
Your links should be using a relative path.
ie:
Code:

<a href="/pictures/image1.jpeg">
They shouldn't be using a full path
ie:
Code:

<a href="www.somesite.com/pictures/image1.jpeg">
So you shouldn't need to change any (maybe many) of your links.

SharpyWarpy 12-17-2011 08:16 PM

Yeah, I know what they should be but being the stickler that I am I always use the full path like this:
<img src="http://www.wfeca.net/users/rbandmb/image.jpg">

fukawi1 12-17-2011 09:27 PM

I would take a backup of your site first.
Code:

sed "s|http://www.wfeca.net||g" *.html
will remove "http://www.wfeca.net", that is, any instance it finds within any html files)
Code:

sed "s|http://www.wfeca.net|http://www.newurl.com/|g" *.html
will change the first address into the new address.

Ordinarily, sed would use forward slashes as a delimiter, but you can alternatively use colons, or pipes to avoid having to escape out any forward slashes/colons in the URL. So to use forwardslashes, it would look like:
Code:

sed "s/http:\/\/www.wfeca.net//g" *.html
I would take a backup of your site first.
The above commands will output the changes to the screen so you can review them. (you may want to pipe it to less to read them all)

Using
[code]sed -i [code]
will make the changes to the files themselves.

Did i mention that you should take a backup beforehand? :p

chrism01 12-20-2011 08:07 PM

If you own the domain name you are using (which would be normal), then you don't need to change anything, as you should be getting the DNS entry txfrd to the new ISP.

SharpyWarpy 12-21-2011 05:24 AM

Quote:

Originally Posted by fukawi1 (Post 4552707)
I would take a backup of your site first.
Code:

sed "s|http://www.wfeca.net||g" *.html
will remove "http://www.wfeca.net", that is, any instance it finds within any html files)
Code:

sed "s|http://www.wfeca.net|http://www.newurl.com/|g" *.html
will change the first address into the new address.

Ordinarily, sed would use forward slashes as a delimiter, but you can alternatively use colons, or pipes to avoid having to escape out any forward slashes/colons in the URL. So to use forwardslashes, it would look like:
Code:

sed "s/http:\/\/www.wfeca.net//g" *.html
I would take a backup of your site first.
The above commands will output the changes to the screen so you can review them. (you may want to pipe it to less to read them all)

Using
[code]sed -i [code]
will make the changes to the files themselves.

Did i mention that you should take a backup beforehand? :p

Thank you very much, fukawi1. Yes I have already backed up everything with wget --mirror. I didn't know about the use of colons and/or pipes as alternatives for forward slash as a delimiter. That would make things less confusing. Thank you for that too.


All times are GMT -5. The time now is 02:04 AM.