Hello,

I'm quite nub in web development, so be gentle please. If this place is wrong for such problems point me to a more appropriate resource please.

To became more familiar with web-programming I found good (as I thought) area for self-improvement. One of my friends owns web project. This project was developed during last 15 years with one programmer who seems to be slightly tired and probably is needed for backup. I've tried (for the very beginning) copy all stuff to the new development environment and found that project consists of several tens of sites: site1.domain.name, site2.domain.name, etc. So the problem that sources contains about million hrefs to the absolute addresses. So I need any advices how to reorganize this project to make it more convenient like project.anotherdomain.name/site1 or any other approaches to moving project to the development environment. Project is mostly in PHP+mysql, so I'm affraid that db also can contain absolute addresses.

Dani AI

Generated

For @Denis_2: with dozens of subdomain sites and lots of absolute URLs, the least invasive way to get a working dev copy is to make the dev environment present the same hostnames the sites expect. That avoids mass edits to files and the database. For a small number of hostnames use your machine's hosts file; for many subdomains use a local DNS (dnsmasq or an equivalent) or a wildcard DNS service and configure your webserver (virtual hosts/server blocks) or a container router to route each hostname to the matching site. This preserves links, cookies, and most serialized data so you can test behavior without changing production content. As pointed out, having centralized settings makes later changes simpler; the hostname-preservation approach delays any big rewrite work.

If hostname preservation is not possible, do safe, staged search-and-replace on a copy of the database and files. Never run blind SQL REPLACE on production data: PHP serialized strings, JSON, or base64 blobs break if lengths or encodings change. Use a tool or a small script that attempts to unserialize and then performs replacements before reserializing; test on a DB dump first. Example pattern (very small proof-of-concept):

<?php
function safe_replace($value,$search,$replace){
  $maybe = @unserialize($value);
  if ($maybe !== false || $value === 'b:0;'){
    array_walk_recursive($maybe,function(&$v) use($search,$replace){
      if (is_string($v)) $v = str_replace($search,$replace,$v);
    });
    return serialize($maybe);
  }
  return str_replace($search,$replace,$value);
}

General checklist before any migration: work from full file + DB backups, run changes against copies only, disable outgoing emails and payment hooks in dev, reset credentials and API keys, verify uploads and media paths, and run smoke tests site-by-site. For longer term, add central base-URL configuration and version control, or adopt containerized routing (Traefik/nginx-proxy) so dev setups can mirror production hostnames without rewriting content.

Recommended Answers

All 2 Replies

I use config files to set the host name for the site as well as other site wide settings. To be specific, config.php which sets the hostname & database details then all web files refer to config.php for the host name & login details - hopefully he has these files for the websites he made.

If he has hardcoded the IP address or hostnames into the websites files then i'd suggest notepad++ for a major search & replace party. You could automate the search replace one site at a time quite well but it will be a good lengthy job checking each site works and fixing the oddities in the coding that could come up, like I sometimes put URL's in CSS or JS for instance, or some parts use http and others https.

Thank you. I'll go this way. I had a hope that it's possible to use some tricks. May be requests redirection or something like this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.