The next .htaccess code redirects example.com (from /public_html root folder) to the subdomain1.example.com (to /public_html/subdomain1 subdolder) and an old page register to a new one at subdomain1.example.com/enroll. So far so good! But, I have also a subdomain subdomain2.example.com (in the /public_html/subdomain2 subfolder) that instead of his normal URL is redirected to the subdomain1.example.com/subfolder2, that not exists. Why this happens and how to avoid this?

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://subdomain1.example com/$1 [R=301,L]
Redirect 301 /register http://subdomain1.example com/enroll

This is the adopted answer, thanks to @anubhava:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} !subdomain.example.com [NC]
RewriteRule ^(.*)$ http://subdomain.example.com/$1 [R=301,L,QSA]

Sourse: https://stackoverflow.com/a/19323457/1354580

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.