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?

1 Answer 1

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.