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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With