# Below is for subdomains RewriteCond %{ENV:REDIRECT_STATUS} ^$ # Make sure it's not (!) a request to wwws1a.example.com.sg. RewriteCond %{HTTP_HOST} !^wwws1a\.example\.com\.sg$ [NC] # If it is a sub domain request (subdomain.example.com.sg) RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.example\.com\.sg$ [NC] # and it is a request for / (the site's root) rewrite the request to /xxx/yyy/subdomain.html RewriteRule ^/$ /xxx/yyy/%1.html [PT,L]

# Below is for subdomains RewriteCond %{ENV:REDIRECT_STATUS} ^$ # Make sure it's not (!) a request to wwws1a.example.com.sg. RewriteCond %{HTTP_HOST} !^wwws1a\.example\.com\.sg$ [NC] # If it is a sub domain request (subdomain.example.com.sg) RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.example\.com\.sg$ [NC] # and it is a request for / (the site's root) rewrite the request to /xxx/yyy/subdomain.html RewriteRule ^/$ /xxx/yyy/%1.html [R=301,L]

RewriteEngine On # Below is for subdomains RewriteCond %{ENV:REDIRECT_STATUS} ^$ # Make sure it's not (!) a request to wwws1a.example.com.sg. RewriteCond %{HTTP_HOST} !^wwws1a\.example\.com\.sg$ [NC] # If it is a sub domain request (subdomain.example.com.sg) RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.example\.com\.sg$ [NC] # and it is a request for / (the site's root) rewrite the request to /xxx/yyy/subdomain.html RewriteRule ^/$ /xxx/yyy/%1.html [R=301,L]

This is for the second requirement. I'm thinking it should be independent of the first?

# If it's not a request to an existing file RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-f # and if it's not a request to an existing directory RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-d # and it matches "pattern1" rewrite to /abc/def?type=pattern1. RewriteRule ^/([\w\s\-&\(\)\.]+)$ /abc/def?type=$1[PT,L]

# Enable the rewrite engine RewriteEngine on RewriteLogLevel 9 RewriteLog "/opt/ihs/v61/ihss1a/logs/rewrite.log" # Below is for subdomains RewriteCond %{ENV:REDIRECT_STATUS} ^$ # Make sure it's not (!) a request to wwws1a.abc.com.sg. RewriteCond %{HTTP_HOST} !^wwws1a\.abc\.com\.sg$ [NC] # If it is a sub domain request (subdomain.abc.com.sg) RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.abc\.com\.sg$ [NC] # and it is a request for / (the site's root) rewrite the request to /xxx/yyy?page=subdomain. RewriteRule ^/$ /web/aa17/%1.html [PT,L]

# Below is for friendly company URL # If it's not a request to an existing file RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-f # and if it's not a request to an existing directory RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-d # and it matches "company" rewrite to /webapp/AA17abc/ipd-app/public/companies/myCompany.jspa?name=company RewriteRule ^/([\w\s\-&\(\)\.]+)$ /webapp/AA17abc/ipd-app/public/companies/myCompany.jspa?name=$1 [PT,L]

The above behaves quite strangely. When I requested for http://fnbs1a.abc.com.sg, according to the rewrite.log, it can rewrite to => /web/aa17/fnbs1a.html. However, instead of opening the page (which exists), rewrites continues.

It continues with a different URL (/webapp/AA17abc/index.jsp). Is it related to the original request?

# A new request, so mod_rewrite starts.... (2) init rewrite engine with requested uri /webapp/AA17abc/index.jsp# The first rule is tested, it does not match, nothing happens.... (3) applying pattern '^/$' to uri '/webapp/AA17abc/index.jsp'# The second rule is tested, it does not match, nothing happens.... (3) applying pattern '^/([\w\s\-&\(\)\.]+)$' to uri '/webapp/AA17abc/index.jsp'# The request continues.... (1) pass through /webapp/AA17abc/index.jsp

It continues with a different URL (/webapp/AA17abc/index.jsp). Is it related to the original request?

The URL (/webapp/AA17abc/index.jsp) is the home page. I am expecting it to open the URL /web/aa17/fnbs1a.html. The request to http://motors1a.abc.com.sg works and the URL /web/aa17/motors1a.html is opened without continuing to the URL /webapp/AA17abc/index.jsp.

It's normal, all requests are tested against the RewriteRules

How do I make the rules independent of each other? How do I stop the rewrite process for requests other than those I keyed in the URL bar?