You rebuild a website with HTML and PHP by separating the job into two tracks that run in parallel but finish in sequence: first you capture and clean the existing content and URLs, then you replace the static markup with PHP templates that render that content. The key condition is that every old URL must keep working—through preserved paths, redirects, or both—or you'll lose traffic and search rankings no matter how good the new code is. HTML defines the structure of each page; PHP decides which content goes into that structure and handles forms, sessions, and shared includes. Done in the right order, the rebuild is reversible at every stage.

Below is a workable sequence for a small-to-midsize site, with the reasoning behind each step, the failure modes that actually bite people, and the checks that tell you a stage is done.

Decide what "rebuild" means before writing any code

A rebuild can mean three quite different projects, and mixing them up is the most common reason these efforts stall:

A code rebuild. The content stays identical; you're replacing hand-coded static HTML pages with PHP templates, includes, and a routing layer. Scope is predictable. A content rebuild. You're rewriting, merging, or deleting pages while also changing the code. Scope is larger and the risk to SEO is real because URLs and page inventory change. A platform rebuild. You're moving off a CMS, site builder, or framework onto plain PHP. This is where data export and redirect mapping become the hard part.

Write down which one you're doing. If it's a code rebuild only, you can promise yourself that the visible text won't change—and that constraint makes verification much easier. If content is changing too, snapshot the current site first (a full crawl plus a database dump if you have one) so you can compare old and new page inventories later.

Also settle the stack basics now: the PHP version your host offers, whether you have database access, whether you can set rewrite rules, and whether the site is served over HTTPS. Those four answers determine half the technical decisions ahead.

Inventory the existing site instead of guessing

You can't rebuild what you haven't measured. Before touching templates, produce a page inventory.

Prerequisite: access to the current site (files or crawl) and, ideally, a list of URLs from your analytics or server logs.

1: Crawl the site with a tool or a simple script and export every reachable URL. 2: Cross-reference against your analytics top pages and any sitemap files. Crawls miss orphan pages that only receive traffic from external links; analytics catches them. 3: For each URL, note: page title, primary heading, whether it has a form, whether it's a landing page with paid traffic, and approximate monthly visits. 4: Flag duplicates and near-duplicates (the same content at /page and /page/ or /page.html and /page.php). These need a canonical decision, not a copy. 5: Record which URLs are linked externally. You can't see every inbound link, but you can check your analytics referral sources and any known partner links.

Success check: your inventory count roughly matches your sitemap count plus known orphans, and the top 20 URLs by traffic are all on the list. If the numbers diverge wildly, keep crawling—there may be paginated archives, tag pages, or old directories you'd otherwise destroy.

This inventory becomes your redirect map's source of truth. Everything downstream depends on it.

Plan the URL map and redirects first

This is the step people skip, and it's the one that determines whether the rebuild preserves your search visibility. Search engines and users both treat a changed URL as a new page unless you tell them otherwise with a permanent redirect.

Build a spreadsheet with three columns:

Old URL (exact path, including trailing slash behavior) New URL (the PHP route that will serve the equivalent content) Status (301 permanent, 302 temporary, or "no change needed")

Rules that hold up in practice:

Prefer keeping the old URL structure. If /about.html becomes /about served by PHP, that's still a change—301 it. Map one old URL to exactly one new URL. Don't point many old pages at the homepage unless the content genuinely merged; mass-redirecting everything to the root is treated as a soft 404 and wastes the old pages' value. Handle the .html/.php extension problem deliberately. If you're moving from .html files to PHP-rendered routes without extensions, every old URL needs a rule. Keep redirects in one place—server config (Apache .htaccess or nginx location blocks) or a PHP-level router. Don't split them across both unless you have a clear reason, because debugging doubled redirects is miserable.

A simple .htaccess example for an Apache host, redirecting old static pages to PHP routes:

For many URLs, a RewriteRule pattern or a PHP router with a lookup array scales better than hundreds of Redirect lines.

Failure check: request an old URL with curl -I and confirm you see a single 301 pointing to the correct new path, followed by a 200 at the destination. A chain of 301 → 301 → 200 works but leaks a little signal; a 301 to a 404 is a broken redirect.

Build the PHP foundation: structure, includes, and routing

Now the actual code. Keep the early structure boring and legible; cleverness comes later, if ever.

A minimal, maintainable layout looks like this:

index.php reads a request parameter, validates it against an allowlist, and includes the matching content file between the shared header and footer. The allowlist is the security-critical detail:

Two things this does right: it never builds a file path from raw user input (which is how directory traversal happens), and it returns a real 404 status, not a 200 page that merely says "not found."

Better still, put the routing in a single front controller and use rewrite rules so URLs stay clean:

Then map the route string to a content file inside PHP. This keeps every request flowing through one place where you can add redirects, logging, and security headers consistently.

Success check: the homepage renders through the template, a nonexistent route returns a 404 status, and view-source shows the header and footer included exactly once per page.

Convert static HTML into reusable templates

Take your most common page type first—usually a content page with a heading, body text, and a sidebar or footer CTA. Copy its HTML into a template file and replace the parts that vary with PHP echoes.

Three practical habits make this stage go fast:

Keep the HTML semantic. Use one per page, real , , and elements, and heading levels in order. A rebuild is the cheapest moment to fix a decade of soup. Escape everything you output. Wrap dynamic values in htmlspecialchars($value, ENT_QUOTES, 'UTF-8'). This isn't optional; it's the single most effective defense against cross-site scripting in a hand-built PHP site. Separate configuration from templates. Database credentials, the site base URL, and environment flags belong in a config.php that the web server can't serve directly (place it outside the document root, or block it in server config).

If your content lives in files, each content/*.php file can be mostly HTML with a few variables set at the top. If it lives in a database, the template pulls a row by slug. Start with files; move to a database when you actually need querying, editing by non-developers, or shared data across pages.

One caution: don't mix inline styles copied from the old site into the new templates wholesale. If the design is changing, do the markup and the CSS as separate passes—mixing them means you can't tell whether a layout bug comes from the PHP output or the new stylesheet.

Success check: build one page end to end, then a second page by reusing the template. If the second page requires copy-pasting template code, your includes aren't factored correctly yet.

Migrate content and data without losing anything

If there's a database, this stage is a data migration. The pattern that works:

1: Export the old content (SQL dump, CSV, or API export) into a staging location. 2: Inspect the export for encoding problems, HTML entities stored in the database, and fields nobody maintains. Old CMS data is often messier than it looks. 3: Transform into your new schema, keeping the old identifier on each record so you can trace back. 4: Import into the new database or write out new content files. 5: Verify row counts and spot-check the trickiest records—the longest pages, the ones with embeds, the ones with images.

For image and file assets, keep the same folder structure where possible. If you must reorganize, update references in the same pass and check for broken images afterward; a crawler that reports broken assets is worth running here.

Failure modes worth naming: character encoding mismatches (UTF-8 data read as Latin-1 produces garbled text), double-escaped HTML (you'll see literal <p> in rendered pages when you unescape twice), and lost uploads that lived outside the database. Check all three explicitly rather than discovering them after launch.

Success check: a diff of old versus new rendered text for ten representative pages shows only intended changes. If you're doing a pure code rebuild, that diff should be empty.

Handle forms, sessions, and dynamic features safely

Static HTML did nothing; PHP will now accept input, and input is where small sites get compromised. The essentials, in plain terms:

Validate on the server. Client-side checks are a convenience, not a control. Reject unexpected values, cap input lengths, and validate email formats with PHP's filter functions. Escape on output. As above—escape at render time, not at storage time, so one record can be safely shown in HTML, email, and JSON. Use CSRF tokens on forms that change state, and check them before acting. Prepared statements for every database query. Concatenating user input into SQL is how injection happens; PDO or mysqli prepared statements remove the class of bug entirely. Hash passwords with password_hash() and verify with password_verify(). Never store reversible or hand-rolled hashes. Set sessions securely: session_start() before output, regenerate the ID on login, and mark cookies HttpOnly and Secure when you're on HTTPS.

Contact forms need spam handling too. A honeypot field plus a timestamp check catches most bots without forcing visitors into a puzzle. If you send mail from PHP, verify delivery to a real inbox before launch—mail sent from a new server is often flagged, and that's a configuration problem (SPF/DKIM at your host), not a code problem.

Success check: submit every form with valid data, then with deliberately broken data, then with a scripted request that skips the browser. The first should succeed, the second should show errors without crashing, and the third should be rejected.

Test on staging, then launch with a rollback path

Set up the new site on a staging subdomain that isn't publicly linked and, ideally, is blocked from indexing. Then work through a checklist:

Every URL in your inventory returns 200 at the intended destination or a single 301 to it. The redirect map has no loops and no chains longer than one hop. All internal links point to the new paths, not the old ones. Forms deliver, and error messages render correctly. Pages load acceptably on a throttled connection; PHP output shouldn't add noticeable latency. The site works with JavaScript disabled for content pages, since HTML and PHP should carry the core experience. HTTPS is enforced, and no mixed-content warnings appear in the browser console.

Launch in a controlled way: back up the old site completely (files and database), deploy during low traffic, verify the homepage and the top ten pages immediately, then verify a sample of old URLs with curl -I. Keep the old site archived for at least a few weeks—not serving it, but available—so rollback is a file restore, not a rebuild.

Stop condition: if the site handles payments, stores sensitive personal data, or has regulatory obligations, the above is enough to plan and build but not enough to launch without a security review. Bring in a qualified developer or security professional before going live in that case.

Common Ways PHP Rebuilds Go Wrong

A few failures recur often enough to plan around:

Broken redirects after a URL strategy change. Fixed by building the map first, as covered—but the deeper fix is deciding the URL scheme before templates exist. Path bugs on the new host. Absolute file paths that worked on one server break on another; relative includes fail depending on the working directory. Use DIR for includes and a configured base URL for links. Error pages that return 200. A "page not found" screen that responds with HTTP 200 tells search engines the page exists. Always http_response_code(404). Configuration files exposed. A config.php in the document root can sometimes be downloaded as plain text if PHP isn't executing for some reason. Keep secrets outside the web root. Render performance regressions. Including a dozen files per request adds up. It's rarely a problem for small sites, but if pages feel slow, measure before optimizing—usually the fix is enabling PHP's opcode cache, which most hosts do by default.

Estimate the Effort Realistically

For a site of 30–80 pages with one form and no database, a careful single developer can complete the sequence above in roughly two to four weeks of focused work, with the redirect planning and content migration taking longer than people expect relative to template building. Sites with user accounts, e-commerce, or thousands of pages scale up sharply, and the data migration typically dominates.

A rough rule: templates are maybe 30% of the job; inventory, content movement, redirects, and verification are the rest. Budget accordingly, and resist the urge to rewrite copy mid-rebuild unless the content change was an explicit goal—it turns a verifiable code migration into an open-ended editing project.

The rebuild is done when every old URL resolves correctly, every form works under abuse, and the staging-versus-production diff shows only what you intended to change. That's a higher bar than "the new homepage looks right," and it's the difference between a site that quietly keeps its traffic and one that quietly loses it.