An .htaccess 301 redirect tells browsers and search engines that a URL has moved permanently. Apache returns a 301 response with a destination URL, and the client makes a new request to that address. A 302 response means a temporary redirect, not a permanent move.
We cover exact page matches, directory moves, domain migrations and pattern-based redirects below. These are configuration examples for your own server; choose only the rule that matches your migration instead of pasting every example into one file.
Before editing: map the old URL to the right destination
Write down the old path, its intended replacement and whether additional path segments should survive. Moving /old-guide.html to a new article is different from moving an entire directory. Sending everything to a homepage is not a substitute for planning useful destination pages.
Google treats permanent server redirects as a strong signal that the target should be canonical. That is not a promise of unchanged rankings. Use redirects for actual moves and test the result rather than assuming the status alone solves a migration.
If the move involves a different name, our domain redirect guide covers the broader setup. You can use our domain lookup tool while reviewing registration information, but it cannot confirm that a web redirect works.
Need the domain first?
Runs the same live check as the front page. If it is taken we will show you when it expires.
Step 1: locate and back up the correct file
The examples below belong in the site's root .htaccess file on an Apache server that permits the relevant directives. Download a backup first. Use the document root assigned to the old site, because requests for the old URL must reach the server that sends the redirect.
The filename starts with a dot, so your file manager may hide it. Preserve existing application and security rules. If you need background on directory-level configuration, read what .htaccess does. If your hosting uses another server, ask for its supported redirect configuration instead of assuming this file applies.
For WordPress or another routed application, consider how the new rule interacts with its existing routing. Avoid adding equivalent redirects in multiple systems without checking which one responds. A control-panel redirect, plugin and server rule can otherwise make troubleshooting unnecessarily difficult.

Step 2: redirect one exact page
Use RedirectMatch with start and end anchors when only one path should match:
RedirectMatch 301 ^/old-guide\.html$ https://example.com/new-guide/Replace the destination with your actual new URL. In the pattern, ^ marks the start, $ marks the end, and the escaped dot means a literal dot. This avoids unintentionally treating the old page as a directory prefix.
The simpler form is also valid for a prefix-based move:
Redirect 301 /old-guide.html https://example.com/new-guide/However, Apache's Redirect matches complete path segments and appends additional path information. It is not an exact-match regular expression. That distinction matters when a URL might also have trailing segments. Choose the anchored example when exact matching is the requirement.
Step 3: move a directory and retain the rest of the path
When the directory structure remains equivalent, use matching trailing slashes:
Redirect 301 /old-directory/ https://example.com/new-directory/A request for /old-directory/manual.pdf is directed to https://example.com/new-directory/manual.pdf. The appended part is useful only if that file or page exists at the target. Test a nested path, not just the directory landing page.
This example does not separately match the slashless /old-directory path. If you need to map that exact URL as well, add an explicit rule for it and test how your server handles directory-slash normalization. Do not assume every spelling takes the same route.
Step 4: move a whole domain without losing paths
If the old domain has its own document root, the simple whole-site pattern is:
Redirect 301 / https://new.example/This preserves the path after the initial slash. For instance, /contact/ goes to https://new.example/contact/, rather than every page being collapsed onto the new homepage. The old domain must still reach this server; changing DNS alone does not send an HTTP redirect.
Do not use this unconditional rule in a shared document root serving both old and new domains. Requests to the destination could match it again. Separate the old site's configuration or use a host-conditional rule designed for that setup. Our expired-domain .htaccess guide discusses that use case.
Step 5: use a pattern only when every target exists
For a genuine extension migration where the replacement pages exist, an anchored pattern can map HTML paths to PHP paths:
RedirectMatch 301 ^/(.+)\.html$ https://example.com/$1.phpHere, $1 reuses the captured path. This is not a general instruction to rename all URLs: it is appropriate only when those replacements are real and intentional. Check a representative nested page as well as a top-level page before making the rule permanent.
For more complex conditions, Apache offers mod_rewrite. Prefer a simpler Redirect or RedirectMatch when it expresses the intended mapping clearly. Do not mix snippets from different contexts without checking their matching rules.
Step 6: verify status, destination and final content
- Save the edited file and request the old URL.
- Inspect the first response: it should be 301 with the intended Location header.
- Follow the redirect and confirm the final page loads successfully.
- Test unrelated URLs to catch overbroad matching.
- Check nested paths, query strings and your hostname variants where applicable.
- Restore the backup if you introduce server errors or loops.
Use browser network tools or a request such as curl -I https://old.example/old-guide.html to inspect response headers. For a full chain, curl -IL follows redirects. A successful browser landing page alone does not reveal whether several unnecessary redirects happened first.
Permanent redirects can be cached, so evaluate uncertain mappings with temporary rules before switching to 301. If a browser still follows an old destination after a correction, inspect a fresh request rather than assuming the current server file is unchanged.
Common questions
Does a redirect move the website's files?
No. It tells the client where to request content. You still need the destination website, working hosting and the intended pages in place.
Is forcing HTTPS the same configuration?
It is a redirect use case with an extra condition: HTTP should change to HTTPS without repeatedly redirecting HTTPS requests. Follow our HTTPS .htaccess guide rather than using an unconditional same-site rule.