LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-17-2011, 07:14 PM   #1
SharpyWarpy
Member
 
Registered: Feb 2003
Location: Florida
Distribution: Fedora 18
Posts: 862

Rep: Reputation: 91
Smile 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.
 
Old 12-17-2011, 07:32 PM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 192Reputation: 192
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.
 
Old 12-17-2011, 08:16 PM   #3
SharpyWarpy
Member
 
Registered: Feb 2003
Location: Florida
Distribution: Fedora 18
Posts: 862

Original Poster
Rep: Reputation: 91
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">
 
Old 12-17-2011, 09:27 PM   #4
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 192Reputation: 192
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?
 
Old 12-20-2011, 08:07 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,850

Rep: Reputation: 2585Reputation: 2585Reputation: 2585Reputation: 2585Reputation: 2585Reputation: 2585Reputation: 2585Reputation: 2585Reputation: 2585Reputation: 2585Reputation: 2585
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.
 
Old 12-21-2011, 05:24 AM   #6
SharpyWarpy
Member
 
Registered: Feb 2003
Location: Florida
Distribution: Fedora 18
Posts: 862

Original Poster
Rep: Reputation: 91
Quote:
Originally Posted by fukawi1 View Post
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?
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Block URLS/websites or Allow only Specific Sites in a Slack anoopch Slackware 4 10-21-2010 01:22 PM
sed: how to change MAC address string with sed cold Linux - Software 5 08-02-2010 07:43 AM
Software to download websites X pages deep? vargadanis Linux - Software 8 03-01-2008 08:20 AM
Changing a Websites Domain Name chocolate85 Linux - Server 2 02-01-2008 03:37 PM
perl -MCPAN -e shell, resetting or changing mirror urls msteudel Linux - Software 3 04-23-2004 09:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration