You can use mod_rewrite in the website’s root .htaccess file to capture the path after photogallery/, append it to the new domain, and send visitors to the new URL with a 301 permanent redirect. With the supplied example rule adapted for this case, www.example.com/photogallery/2010/January-Spring-Photos/ would redirect to example.site/2010/January-Spring-Photos/. This redirects the specified subdirectory while preserving the remaining path. For SEO, the source discussion recommends a 301 redirect, but that does not guarantee rankings or other metrics will remain unaffected.
Place the rule in the root .htaccess file
If the website uses .htaccess and mod_rewrite, you can adapt the source example as follows, using example.site as the destination domain:
RewriteEngine On
RewriteRule ^photogallery/(.*)$ http://example.site/$1 [L,R=301,QSA]
Place this rule in the website’s root .htaccess file, not inside the photogallery folder. The rule is written for the root directory, so do not move it to another directory level without accounting for the change in location.
The example retains HTTP from the source and changes only the destination domain to example.site. In your actual configuration, the destination URL should use the same protocol as the new site. The source material does not describe the new site’s HTTPS configuration.
Capture and reuse the remaining path
In the rule, ^photogallery/ specifies the subdirectory to handle, (.*) captures everything after it, and $1 inserts that captured content into the destination URL. The new URL therefore drops the photogallery directory level but preserves the remaining path, rather than sending every visitor to the new site’s homepage.
- /photogallery/2010/January-Spring-Photos/ maps to /2010/January-Spring-Photos/ on the new domain.
- /photogallery/ maps to the root path on the new domain because nothing follows it.
- /news/ does not match this rule’s subdirectory prefix and will not be redirected by this rule.
Note that the rule requires a slash after photogallery, so it does not match /photogallery. If you also need to handle URLs without a trailing slash, the example above does not cover that case.
A 301 signals a permanent move, not guaranteed SEO results
The source discussion on site migration recommends 301 permanent redirects, configured either with regular expressions or for individual links. Because the path mapping is consistent in this case, a single rule can handle the redirects in bulk without listing URLs page by page.
However, preserving the path does not mean that corresponding content already exists on the new site. For example, after an old gallery redirects to the same path on the new domain, you should still verify that the destination is the intended page. The source material does not describe how content is organized on the new site or provide sufficient grounds to promise an SEO recovery timeline. Here, a 301 signals a permanent move; it does not guarantee rankings.
Subdirectory redirects: perspectives from across the web
Can a rule for redirecting an old phpBB site to a static page be applied directly to a photo gallery migration?
It should not be applied directly. The phpBB example in the public discussion uses ^view* for matching and points to a fixed static HTML page; it does not append the path after the gallery subdirectory to the destination URL. It suits the site-closure scenario described by that contributor, but should not be treated as an example of preserving the gallery’s remaining path.
References
- Redirect traffic from a specific subfolder to a different domain with preserved path in .htaccesswebmasters.stackexchange.com — Discusses: Can a rule for redirecting an old phpBB site to a static page be applied directly to a photo gallery migration?
- Moving website ranked website from .CA to .COMwww.warriorforum.com — Source used in the article above.
- Redirect traffic from a specific subfolder to a different domain with preserved path in .htaccesswebmasters.stackexchange.com — Source used in the article above.
