Code guides

Move an old page and a folder with Apache redirects

·

A shop has moved its winter sale page and needs a temporary redirect for its old guides folder. The first rule matches one path. The second sends each guide to the corresponding location under a new prefix.

.htaccess Redirect Generator

Redirect the sale page and guides folder

Choose Load example. The first line is 301 exact /winter-sale.html /sales/winter. The second is 307 prefix /old-guides /guides. Select Generate redirect rules to produce the Apache directives.

The first line uses RedirectMatch with start and end anchors. The escaped dot matches the literal dot in winter-sale.html. The second uses Redirect so everything after the old-guides segment is appended to /guides.

Apache HTTP Server 2.4 mod_alias directives

Compare responses on a staging host

Copy the rules into the document-root .htaccess file on a staging Apache server with mod_alias and the FileInfo override enabled. If you download the file, save htaccess.txt as .htaccess. Request /winter-sale.html and check that the response status is 301 and the Location path is /sales/winter.

Request /old-guides/packing.html?lang=en and check for status 307 and a Location ending in /guides/packing.html?lang=en. Try /old-guides-new to confirm that it stays outside the prefix rule.

Apache HTTP Server 2.4 mod_alias directivesApache HTTP Server 2.4 AllowOverride directive

Check rule order and redirect chains

Put specific rules ahead of a broader prefix that covers them. The generator warns when a later rule shares a matching path. If a destination may lead to another listed rule, follow the chain on your staging server and check that it ends on the intended page.

Apache HTTP Server 2.4 mod_alias directives

Common questions

When should a temporary redirect use 307?

Use 307 when the move is temporary and clients should keep their original request method when following it.

Can one generated file contain exact and prefix rules?

Yes. Put each rule on its own line and order rules as Apache should match them.

Sources

Put it into practice.

Related guides