I'm struggling with a .htaccess mod_rewrite challenge. Help is appreciated.
I want the following 301 redirects to work:
- mysite.com > https://newsite.com/subdirectory/
- mysite.com/old_page_1/ > https://newsite.com/subdirectory/new_page_1/
- mysite.com/old_page_2/ > https://newsite.com/subdirectory/new_page_2/
- mysite.com/old_page_3/ > https://newsite.com/subdirectory/new_page_3/
- mysite.com/anything_else > https://newsite.com/anything_else
I'm struggling with the order, or something. Here's my code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/?old_page_1/? https://newsite.com/subdirectory/new_page_1/ [R=301,L]
RewriteRule ^/?old_page_2/? https://newsite.com/subdirectory/new_page_2/ [R=301,L]
RewriteRule ^/?old_page_3/? https://newsite.com/subdirectory/new_page_3/ [R=301,L]
RewriteRule ^/? https://newsite.com/subdirectory/ [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$
RewriteRule ^(.*)$ https://newsite.com/$1 [R=301,L]
</IfModule>
The first 4 rewrites work, but then the anything_else part is broken by the 4th rewrite.