How can you set up 301 redirects from old-domain pages to different paths and troubleshoot failures?

ProcrustesPR

When paths differ between an old domain and a new website, you can map each old path to a full URL on the new domain in the .htaccess file on the old domain’s server. You do not need to keep the original directory structure. If a rule does not take effect, first check the destination, then check rule order, whether Apache allows .htaccess files, and the file’s permissions and location. The configurations below come from Apache scenarios in public discussions and will not work as written in every hosting environment.

ProcrustesPRProcrustesPRHow should you balance CNAME convenience and performance?

Different directory structures: specify the new page’s URL directly

For example, a public discussion provides this page-specific configuration to redirect oldDomain/oldDir/file.php to newDomain/differentDir/file.php:

redirectMatch permanent ^/oldDir/file.php$ http://www.newdomain.com/differentDir/file.php

Enter the old page’s path on the left and the new page’s full URL on the right. This .htaccess file must be on the server serving the old domain, so the domain itself does not need to appear in the matching path. This setup is useful when the directory structure has changed and you need to specify a destination for each page. A 301 redirect tells users and search engines that the content has a new permanent URL.

Preserve subpaths or redirect everything to the homepage?

Another discussion provides the following configuration for a root-directory .htaccess file:

RewriteEngine On
RewriteRule ^photogallery/(.*)$ http://photos.site.com/$1 [L,R=301,QSA]

In this example, $1 carries the matched subpath over to the new domain. It does not automatically find a new corresponding location for each old page. Removing $1 from the destination and using a fixed homepage URL stops the subpath from being carried over, but also sends multiple old pages to the same page.

A working redirect does not necessarily mean the destination is appropriate. The discussion recommends prioritizing page-by-page mapping. If that is too much work, you can handle important pages first and redirect the remaining subpages to a relevant main page. For example, redirect old gallery pages to the gallery’s main page rather than sending them all to an unrelated website homepage.

When a rule does not work: check the destination and server settings

In a case where the destination ended in /outdoors/trees/129/Tanoak, a respondent suggested that a filename might be missing, but did not confirm that this caused the failure. You cannot tell whether a URL is incorrect from its appearance alone. Try these checks in order:

  1. Check the destination: Look for a missing filename if one is expected. If the target really is a directory, try adding a trailing slash as suggested in the discussion.
  2. Check rule order: Try placing the rule first to see whether other rules are running before it.
  3. Check the Apache configuration: Confirm that .htaccess files are allowed.
  4. Check the file: Confirm that Apache has permission to read .htaccess and that the file is in the correct directory or a parent directory.

These are troubleshooting suggestions from public discussions, not a confirmed diagnosis of the specific case. If the redirect still fails, the available information is insufficient to identify a single cause.

ProcrustesPRProcrustesPRShould you use a 302 redirect to a temporary alias for the new server during a DNS update?

301 redirects from an old domain: perspectives from across the web

Will removing $1 redirect all old gallery pages to the new domain’s homepage?

Yes, but only for gallery pages that match this RewriteRule. Changing the destination to the new domain’s fixed homepage URL and removing $1 prevents the matched gallery subpath from being carried over. However, this sends multiple old pages to the same page. Where corresponding content exists on the new site, page-by-page redirects are preferable. If that is too much work, you can handle important pages first and redirect the rest to the relevant gallery’s main page.

Can an individual old page be redirected to a different path if the new site does not retain the old directories?

Yes. In a suitable Apache environment, the public discussion recommends specifying the page’s old path and the new page’s full URL in the .htaccess file on the old domain’s server. The directory names do not need to match. This file must be on the server serving the old domain, so the domain itself does not need to appear in the matching path. Other pages that need different destinations should each have their own corresponding rule.

Is the lack of an obvious filename in the destination URL the reason the redirect fails?

You cannot tell from the URL’s ending alone. The public discussion suggests that an expected filename might be missing, but does not confirm the cause. If the destination really is a directory, try adding a trailing slash. If the redirect still does not work, temporarily place the rule first to see whether other rules are running before it. Also confirm that Apache allows .htaccess files and has permission to read the file, and that the file is in the correct directory or a parent directory.

ProcrustesPRHow does HSTS protect websites and subdomains?

References

  1. SEO: 301 for a page which has no mirrow path?webmasters.stackexchange.com — Discusses: Is the lack of an obvious filename in the destination URL the reason the redirect fails?
  2. 301 redirect to boost SEO of the site being redirected to?webmasters.stackexchange.com — Source used in the article above.
  3. Redirect traffic from a specific subfolder to a different domain with preserved path in .htaccesswebmasters.stackexchange.com — Discusses: Will removing $1 redirect all old gallery pages to the new domain’s homepage?
  4. SEO: 301 for a page which has no mirrow path?webmasters.stackexchange.com — Discusses: Can an individual old page be redirected to a different path if the new site does not retain the old directories?
  5. How to purge old links in google from an old domainwebmasters.stackexchange.com — Discusses: Will removing $1 redirect all old gallery pages to the new domain’s homepage?

Related articles

How should you balance CNAME convenience and performance?Should you use a 302 redirect to a temporary alias for the new server during a DNS update?How does HSTS protect websites and subdomains?How do SSL certificates protect websites, and why are they needed?Should a Tumblr blog use the platform’s domain or the company’s domain?What types of URLs are there, and what are they used for?When should you use relative or absolute paths in WordPress?What are www subdomains and relative links used for?
ProcrustesPR
ProcrustesPR