I need to have many pages redirect temporarily to an old site via .htaccess as I migrate it.
Do I just need to add this line for each 307 redirect to .htaccess?
Redirect 307 /page_one https://www.oldsite.com/page_one
My entire .htaccess would look like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !/(wp-content/uploads/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Redirect 307 /page_one https://www.oldsite.com/page_one
Redirect 307 /page_two https://www.oldsite.com/page_two
</IfModule>
Yes, you can do exactly this if you are only wanting to redirect specific pages.
However, since this appears to be a WordPress site, you should place these directives outside of the
# BEGIN WordPress..# END WordPressblock, since WP itself will try to maintain this block of directives and might overwrite your directives.These mod_alias directives can be placed before or after the WP code block - it does not matter. mod_alias is processed after mod_rewrite anyway, so the order of the directives in the config file really does not matter.
Note, however, that the
Redirectdirective is prefix-matching and everything after the match is copied onto the end of the target. So, in your example,/page_one/foowould also be redirected tohttps://www.oldsite.com/page_one/foo.If the target URL-path is always the same as the source URL-path then you can use a mod_alias
RedirectMatchdirective with a backreference instead to save repetition. This matches using a regex, rather than simple prefix-matching. For example:This only matches
/page_threeexactly and redirects tohttps://www.oldsite.com/page_three. Where the$0backreference is the entire URL-path that is matched by the preceding regex (2nd argument), ie./page_threein this example.If you are only redirecting GET requests then a 302 (temporary) would suffice, so you could omit the status codes, since 302 is the default: