Now I use a full 302 redirect like this:

Redirect 302 / http://new.site.com/folder/ 

Code 302 is used specifically.

Here I found the code at my request to redirect from anywhere except for a specific folder.

 RewriteEngine on RewriteCond %{REQUEST_URI} !^/somefolder RewriteRule ^(.*) http://new.site.com/ [L,R] 

But how to make it work by code 302?

  • If you believe the documentation , then by default RewriteRule creates a redirect with the code 302. - Yaant

1 answer 1

Everything is simple, you just need to set 302 call forwarding.

RewriteRule is a substitution rule. If the query matches the higher checks and [PATTERN], then the substitution rule applies. Here you can also adjust the behavior using flags. Flags are different, an example of the necessary:

R = 302 - Will be a redirect with the code 302, you can specify a different code
L - This is the last rule, no longer apply transformation rules.

 RewriteEngine on RewriteCond %{REQUEST_URI} !^/somefolder RewriteRule ^(.*) http://new.site.com/ [R=302,L]