I am trying to use mod_rewrite to capture a subdomain, domain, and the arguments passed with the url.
I have multiple domains pointing to a single ip address, with both @ and * wildcard a-records, so that is all setup and ready.
so what I am trying to accomplish is: subdomain.domain.ext/arguments/argument/argument/
I want to capture: subdomain, domain.ext, and all the arguments after the / and place them into 3 separate variables so that the webpage served can differ based on this information.
Here is what I have so far:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([A-Za-z0-9-]+)\.domain\.com$ [NC]
RewriteRule ^([A-Za-z0-9-/]+)/?$ /redirect.php?subdomain=%2&args=$1 [QSA]
RewriteCond %{HTTP_HOST} ^([^./]+)\.domain\.com$ [NC]
RewriteCond %1 !=www [NC]
RewriteRule ^ redirect.php?subdomain=%1 [QSA]
RewriteRule ^/?([a-zA-Z0-9/-]+)$ redirect.php?args=$1 [L]
This works for the following scenario:
subdomain.domain.ext/input/input/input
subdomain.domain.ext
domain.ext/input/input
however, I can't figure out how to capture domain.ext and use that as a variable.
Any help would be appreciated.