17

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?

Malachi
  • 977
  • 6
  • 16
  • 31

1 Answers1

26

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.

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198