Redirect folder to another using htaccess

I have a problem redirecting a folder to a new one. I do not want to use php header () or something like that, I want to achieve this effect using the mod_rewrite module and the .htaccess file.

What I'm trying to do is redirect http://domain.com/test/ to the address http://domain.com/new/ . It does not rewrite, it should simply move the user from the old to the new address. I tried to use:

RewriteRule ^test/(.*) new/$1 

But it gives an error 404, a catalog directory error does not exist. How can I redirect a user without creating another folder?

+4
source share
1 answer

You can use external redirection:

 Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteRule ^test/(.*)$ /new/$1 [L,NC,R=302] 

If you do not want external redirection (without changing the URL in the browser), remove the R flag:

 RewriteRule ^test/(.*)$ /new/$1 [L,NC] 

PS: Please clarify: It not rewriting, it has to just move the user from old to new address

+7
source

All Articles