For these 2 redirects:
www.portalweb.subdominio.cu
(no /backend
) → www.portalweb.cu
www.portalweb.cu/backend
→ www.portalweb.subdominio.cu/backend
There are 2 conditions to check: what is the host and what is the route.
All RewriteCond
are conditions that, if met, allow the following RewriteRule
to be executed (if it also matches).
RewriteEngine On
RewriteBase /
# Todo excepto backend a www.portalweb.cu
RewriteCond %{HTTP_HOST} ^www\.portalweb\.subdominio\.cu$ [NC]
RewriteCond %{REQUEST_URI} !^backend(?:/|$) [NC]
RewriteRule (.*) http://www.portalweb.cu/$1 [R,L]
# www.portalweb.cu/backend a www.portalweb.subdominio.cu/backend
RewriteCond %{HTTP_HOST} ^www\.portalweb\.cu$ [NC]
RewriteRule ^(backend(?:/.*|$)) http://www.portalweb.subdominio.cu/$1 [NC,R,L]
These rules are quite obvious. The flags mean:
-
[NC]
No Case. Ignore uppercase and lowercase.
-
[L]
Last. Do not keep trying more rules.
-
[R]
Redirect. Redirect to another URL (instead of rewriting). This flag makes a temporary redirect (302). If you are interested in a permanent, after you have verified that all works well, you can change it by [R=301]
.