Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess redirect from one subfolder to other subfolder

I know this sounds like so many other questions here, but I can't seem to find the answer.

Say you are on: www.domain.com/folderA/folder2/folder3/

I want that to redirect to: www.domain.com/folderB/folder2/folder3/

So the whole structure stays the same.. it just redirects. Now so far I have:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/folderA [NC]
RewriteRule ^(.*)$ /folderB/$1 [R=301,L]

But when I use that, it'll just do www.domain.com/folderB/folderA/folder2/folder3/

What am I doing wrong? How do I get rid of that folderA?

like image 379
Malachi Avatar asked Feb 15 '13 22:02

Malachi


1 Answers

The pattern ^(.*)$ includes also the prefix folderA. You must specify folderA explicitly in the pattern and capture only the latter part in the RewriteRule. Then you can drop the RewriteCond

RewriteEngine on
RewriteRule ^/?folderA/(.*)$ /folderB/$1 [R,L]

Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.

like image 107
Olaf Dietsche Avatar answered Oct 05 '22 20:10

Olaf Dietsche