Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk10 min

How to Configure .htaccess Redirects on WordPress (Apache 301 Guide)

A practical Apache guide to WordPress .htaccess redirects: verify mod_rewrite, back up the file, place precise rules correctly, test with 302, then deploy 301 redirects safely.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To add a redirect in WordPress’s .htaccess, first confirm the site runs Apache with mod_rewrite, back up the file, put a narrowly matched rule above the generated WordPress block, and test it as a temporary redirect before changing it to R=301. If the site runs Nginx, .htaccess is ignored and you must edit the Nginx server-block configuration instead.

This guide shows where the file belongs, how WordPress’s own rewrite rules work, exact redirect patterns, and how to recover from 404 errors, loops, and migration problems.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What .htaccess does in a WordPress installation

.htaccess is Apache’s distributed, per-directory configuration file. A file in a document root affects requests below that directory; a file in a WordPress subdirectory affects that directory and its descendants. It is not a WordPress database setting and it is not processed by Nginx.

WordPress uses Apache’s mod_rewrite module to turn “pretty” permalinks into requests handled by index.php. The generated rules let WordPress resolve a URL such as /news/example/ without requiring a physical folder named news. Apache evaluates rewrite directives before handing the request to WordPress, so a redirect rule can send an old URL directly to its replacement.

Before editing, identify the actual web server. Some hosts put Nginx in front of Apache, while others run Nginx alone. In an Nginx-only setup, changing .htaccess cannot fix a redirect because Nginx never reads the file. Ask the host which server handles the request and whether Apache overrides are enabled for the WordPress directory.

Requirements and a safe preparation checklist

  • Apache: The site must be served by Apache or an Apache-compatible layer that honors per-directory configuration.
  • mod_rewrite: WordPress identifies this module as the component needed for URL rewriting. If it is unavailable, ask the host to enable it.
  • Correct location: Put the file in the document root or the directory where WordPress is installed. A file in a different directory will not affect the request you are testing.
  • Access: Use SFTP, SSH, a hosting file manager, or another method that preserves the filename’s leading dot.
  • Backup: Download a copy of the current .htaccess before changing it. Keep the backup outside the web root and retain the previous WordPress URL and rewrite settings during a migration.
  • Recovery access: Know how to restore the backup or rename the file if a syntax error causes a server error.

On a Unix-like system, a typical backup command is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
cp .htaccess .htaccess.backup-2026-10-15

Use a date that reflects your actual change. Do not create a second live .htaccess with a similar name and assume Apache will use it; the filename must be exactly .htaccess.

Restore or generate WordPress’s baseline rules

For a WordPress installation in the domain root, the standard generated block is:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

The two conditions allow existing files and directories to be served normally. Other requests are passed to /index.php, where WordPress resolves the permalink. A subdirectory installation has different paths and a different rewrite base, so do not paste the root example unchanged into a site installed at, for example, /blog/.

WordPress can display the rules associated with the selected permalink structure. In the administration area, open Settings > Permalinks and click Save Changes without changing the structure. This regenerates the rewrite configuration when WordPress can write the file. If it cannot, the screen displays lines you can copy into .htaccess manually. Saving permalinks is also a useful way to restore a missing or damaged baseline after you have made a backup.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Where custom redirects belong

Place site-specific redirects outside the # BEGIN WordPress and # END WordPress markers, normally above the generated block:

# Custom redirects first
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^old-page/?$ https://example.com/new-page/ [R=301,L]
</IfModule>

# BEGIN WordPress
...generated WordPress rules...
# END WordPress

WordPress can replace the content between those markers when permalinks are saved. Keeping manual rules outside the markers prevents a routine settings save from deleting them. Apache also evaluates rules in order: a broad front-controller rule can consume a request before a later redirect gets a chance to match it. Put specific redirects before that broad rule.

If the file already has a single RewriteEngine On directive, you can add rules within the existing rewrite context rather than enabling the engine repeatedly. Preserve unrelated host or security directives unless you understand their effect.

Add a redirect from one old URL to one new URL

Test with a temporary status first

Use a temporary redirect while checking the match, destination, and nearby URLs. Replace R=302 with R=301 only after the behavior is correct. Browsers and intermediary caches can retain a 301, making mistakes harder to diagnose.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^old-page/?$ https://example.com/new-page/ [R=302,L]
</IfModule>

Request the old URL in a private browser window or with a tool that does not reuse cached redirects. Confirm the response points to the intended destination, then test the destination itself and a similar path such as /old-page/extra/. The latter should not redirect unless you deliberately designed a pattern that includes it.

Make the redirect permanent

After testing, change only the status flag:

RewriteRule ^old-page/?$ https://example.com/new-page/ [R=301,L]

R=301 tells clients and search engines that the move is permanent. L means “last” for the current per-directory rewrite pass, preventing later rules from processing the same request in that pass. It does not by itself prevent a second request to the destination from matching another rule, so inspect the full rule set for loops.

Match the old path precisely

In a root .htaccess, the pattern is relative to that directory and normally does not begin with a slash. The optional /? accepts either a trailing slash or no trailing slash. Literal dots and other regular-expression metacharacters must be escaped. For example:

RewriteRule ^old-slug/?$ /new-slug/ [R=301,L]
RewriteRule ^download.pdf$ /files/current.pdf [R=301,L]

Use a relative destination such as /new-slug/ when the host stays the same. Use an absolute URL when redirecting to another hostname or when you need to state the HTTPS host explicitly. Do not make the old-path expression broad enough to match the destination.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common redirect designs

Old slug to new slug

A one-to-one slug change is the safest case:

RewriteRule ^old-slug/?$ /new-slug/ [R=301,L]

If the old URL has a directory component, include it in the expression, for example ^guides/old-slug/?$. Keep query strings in mind: Apache normally carries an existing query string to the destination unless the rule explicitly replaces it. Test URLs with and without query parameters if analytics or campaign links are important.

Several old paths to one destination

When a small, known set of obsolete paths has the same replacement, use separate, readable rules:

RewriteRule ^legacy-one/?$ /new-page/ [R=301,L]
RewriteRule ^legacy-two/?$ /new-page/ [R=301,L]

Separate rules make accidental matches easier to spot than one complicated expression. For a large migration, create a reviewed mapping and deploy it in batches rather than guessing a pattern that could redirect valid pages.

HTTP to HTTPS

Canonical HTTPS redirects depend on how TLS is terminated. Use the hosting platform’s documented strategy and test both direct Apache requests and requests passing through a reverse proxy or load balancer. If the proxy terminates SSL but does not pass the correct forwarded-protocol information, WordPress may believe every request is HTTP and repeatedly redirect an already secure request. WordPress documents this reverse-proxy failure mode as an infinite redirect loop.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not add a generic HTTP-to-HTTPS rule until you know which server receives the request and which proxy headers it trusts. Verify the final URL, the scheme WordPress reports, and whether administrative pages remain reachable.

Redirect the domain root to a subdirectory

A site that intentionally serves its application below a directory can redirect the bare root to that directory. Adapt the domain and directory names to the installation, and exclude the target path so it cannot redirect to itself. WordPress’s Apache guidance provides a root-to-subdirectory pattern; treat it as a migration rule, not a substitute for setting the correct WordPress Address and Site Address.

Domain or site migration

Changing the WordPress Address or Site Address is only one part of a move. Review the old and new hostnames, HTTPS termination, installation directory, permalink structure, and trailing-slash convention together. Update redirects and rewrite paths after the new files are in place, retain the old configuration backup, and test representative old URLs, media files, feeds, login pages, and the new home page. A migration can appear to work at the home page while deep links still return 404 errors if the rewrite base or document root is wrong.

Choosing the right redirect mechanism

Mechanism Best use Control and risks
Apache .htaccess Fast redirects for an Apache WordPress site, including requests that should never reach WordPress. Manual ordering and regular expressions; depends on Apache, mod_rewrite, and permitted overrides. A syntax error can make the site unavailable.
WordPress or plugin-level redirect Redirects managed by administrators who do not have server-file access, or rules that depend on WordPress data. WordPress must load before the redirect, so it uses more application resources and cannot help when the rewrite layer itself is broken. Plugin behavior varies.
Nginx server-block rules Sites served by Nginx, including Nginx reverse proxies and Nginx-only WordPress hosting. Managed at the server or hosting level; .htaccess changes have no effect. Reloading configuration normally requires host or administrator access.

Choose the layer that actually receives the request. Do not maintain duplicate rules in several layers without documenting precedence; one layer can redirect to a URL that another immediately rewrites back.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Diagnose 404s, loops, and ignored rules

1. Confirm Apache versus Nginx

If the file is ignored, first confirm the web server. On Nginx, move the rule to the appropriate server-block configuration or ask the host to implement it. An Nginx front end may also pass some requests to Apache, so ask which layer owns the public redirect.

2. Verify mod_rewrite and overrides

WordPress needs mod_rewrite for its normal permalink rules. If the module is missing, ask the host to enable it. Apache must also be configured to permit overrides for the directory; the relevant AllowOverride policy is host-specific. If a known-good rule is ignored despite the file being in the correct directory, have the host verify that policy.

Rank #4
Teacher Record Book
  • Keep track of everything from attendance to test scores
  • Spiral bound
  • Measures 8-1/2" x 11"

3. Regenerate the baseline

Back up the file, then use Settings > Permalinks and save the current structure. Copy the displayed rules manually if WordPress cannot write the file. This separates a broken WordPress front-controller block from a problem in your custom redirect.

4. Check order and exact matching

Place the custom rule above the generated catch-all rule. Confirm that the expression matches the path as Apache sees it: no leading slash in a root per-directory pattern, correct directory prefix for a subdirectory install, and the expected trailing slash. Test a neighboring URL to detect an accidental broad match.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

5. Look for redirect loops

A loop occurs when the destination satisfies the old rule, when HTTP and HTTPS rules disagree about proxy state, or when two host-canonicalization rules point at each other. Follow the complete chain from the original URL to the final response. Make the destination clearly outside the old pattern and ensure only one layer owns each canonicalization decision.

6. Recover from a server error

A malformed directive, missing closing condition, or unsupported option can produce a 500-level error. Restore the backup immediately through SFTP, SSH, or the host’s file manager, then test the site before reintroducing one corrected rule at a time. Do not troubleshoot by repeatedly editing a file that has already taken the site offline.

7. Recheck migration assumptions

For a move or URL-structure change, compare the WordPress Address, Site Address, public hostname, HTTPS state, document root, rewrite base, and trailing-slash policy. A mismatch in any one of these can create a mix of 404s and loops that looks like a single redirect mistake.

Security and long-term maintenance

Some administrators use mod_rewrite to block access to sensitive files or paths. Keep those security directives outside the generated WordPress markers for the same overwrite reason as custom redirects. Review every rule for WordPress Multisite compatibility before deploying it; a pattern that is safe for one site can block another site or network endpoint.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Maintain a short change record with the date, old URL, destination, status code, and reason. Remove temporary rules after a migration is complete, but keep the mapping and backup for rollback. Periodically test a sample of redirects with an uncached client, check that destinations return the intended status, and confirm that no chain has grown through successive migrations.

Quick Recap

SaleBestseller No. 1
SaleBestseller No. 3
Bestseller No. 4
Teacher Record Book
Teacher Record Book
Keep track of everything from attendance to test scores; Spiral bound; Measures 8-1/2" x 11"
$4.89

A practical pre-publish test

  1. Save a dated copy of .htaccess.
  2. Confirm Apache, mod_rewrite, the WordPress directory, and override permissions.
  3. Place the specific rule above the WordPress markers, outside the generated block.
  4. Use R=302 while testing and open the old URL in a private session.
  5. Check the status, Location target, final page, query-string behavior, and a nearby URL that should not match.
  6. Test both trailing-slash forms when the rule allows both, plus HTTP and HTTPS where applicable.
  7. Inspect the complete redirect chain for loops or unnecessary hops.
  8. Change to R=301 only after the results are correct, then retest with a client that is not using a cached response.
  9. Save the final file and record the change so it can be reversed without guessing.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.