I was struggling the last few days to write a proper solution for my .htaccess so that I can redirect (http://www.)domain.com/path/anotherpath to https://www2.domain.com/path/anotherpath.
I have managed to make it work as below:
RewriteCond %{THE_REQUEST} www\.domain\.com\path\anotherpath
RewriteRule (.*) https://www2.domain.com/path/anotherpath [R=301,L]
However, this solution doesn’t seem to work when I need to redirect pages that belong to deeper levels like for example: domain.com/path/anotherpath/level1/level2 (level1 and level2 are dynamic). Now it redirects only when a specific full url is detected.
How can I make this work without defining the full urls in my htaccess?
Any help would be very much appreciated.
Thank you
Enable mod_rewrite and .htaccess through
httpd.confand then put this code in your.htaccessunderDOCUMENT_ROOTdirectory: