0

I am struggling with htaccess redirects from both:

/folder/subfolder/any-value/ and /folder/subfolder/any-value to /another-folder/any-value/

The code below works for

/folder/subfolder/any-value/ to /another-folder/any-value/

But NOT:

/folder/subfolder/any-value to /another-folder/any-value/

RewriteRule ^england/devon-cornwall/(.*)/$ https://www.example.com/large-houses/$1/ [R=301,L]

As an additional crtiera, the URL /folder/subfolder/ should remain untouched.

I have searched high and low to fix the trailing slash issue on the url, but cannot find anything. Please can someone help? Thank you!

Edmund
  • 65
  • 2
  • 10

1 Answers1

0

Try :

RewriteRule ^england/devon-cornwall/(.*)/?$ https://www.example.com/large-houses/$1/ [R=301,L]

/? means the / is optional so it matches both uri with a traling slash and uri without a slash at the end.

Clear your browser cache before testing this

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • Thank you starkeen - I tried that in https://htaccess.mwl.be/ but it suggests that /folder/subfolder/ (england/devon-cornwall/) will also be redirected in that case? – Edmund Feb 26 '18 at 17:23
  • @Edmund That's true. This also redirects all folders and subfolders of `/england/dwvon-cornwall` as you already mentioned in your question. FYI,please don't test htaccess rules on online testers like made with love but instead test them on your live server to get the exact performance status. – Amit Verma Feb 26 '18 at 17:49
  • Thank you, but I'd like /folder/subfolder/ to be untouched, i.e. not redirected? Only child URLs of this string should be redirected. I hope that makes sense! Thanks – Edmund Feb 26 '18 at 18:00