Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect all traffic to temporary domain with 307 redirection

I'm trying to redirect the traffic to my temporary adress. Im using httaccess file to do that. That's the content of it:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^old.domain$
RewriteRule (.*)$ http://new.domain/$1 [R=307, L]

It works if I enter adress: http://old.domain but it won't work with http://old.domain/somenting. It sends then 500 error. If I change R=307 to R=301 it works but I need 307 redirection.

like image 521
Filip Frątczak Avatar asked Sep 16 '13 10:09

Filip Frątczak


People also ask

What is a 307 temporary redirect?

HTTP 307 Temporary Redirect redirect status response code indicates that the resource requested has been temporarily moved to the URL given by the Location headers. The method and the body of the original request are reused to perform the redirected request.

How do you fix temporary redirect 307?

The best way to handle URL redirections is at the server level with HTTP 3xx redirect status code responses. If your site is down for maintenance or unavailable for other reasons, you can redirect it temporarily to another URL with a 307 Temporary Redirect response.

What is the difference between 302 and 307 redirect?

302 is temporary redirect, which is generated by the server whereas 307 is internal redirect response generated by the browser.


1 Answers

Those rules work fine for me, but there's a syntax error in your rewrite rule's flags. You can't have a space after the comma:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^old.domain$
RewriteRule (.*)$ http://new.domain/$1 [R=307,L]
# no space here-------------------------------^
like image 89
Jon Lin Avatar answered Nov 13 '22 21:11

Jon Lin