I have a website that moved from root to a sub domain. Now I need to redirect all forms of previous URLs (with or without www) to the new sub domain format.
Example:
http://www.website.com/ => http://sub.website.com/
http://website.com/ => http://sub.website.com/
http://www.website.com/sample-page/ => http://sub.website.com/sample-page/
http://website.com/images/1.jpg => http://sub.website.com/images/1.jpg
What I found up to now is about redirecting sub domain to root. Can you help me please?
You can use:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^sub\.website\.com$ [NC]
RewriteRule ^ http://sub.website.com%{REQUEST_URI} [NE,L,R=301]