307 redirect in .htaccess is this correct?

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>


Solution 1:

Redirect 307 /page_one https://www.oldsite.com/page_one
Redirect 307 /page_two https://www.oldsite.com/page_two

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 WordPress block, 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 Redirect directive is prefix-matching and everything after the match is copied onto the end of the target. So, in your example, /page_one/foo would also be redirected to https://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 RedirectMatch directive with a backreference instead to save repetition. This matches using a regex, rather than simple prefix-matching. For example:

RedirectMatch 307 ^/page_three$ https://www.oldsite.com$0

This only matches /page_three exactly and redirects to https://www.oldsite.com/page_three. Where the $0 backreference is the entire URL-path that is matched by the preceding regex (2nd argument), ie. /page_three in 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:

RedirectMatch ^/page_four$ https://www.oldsite.com$0