I have a server that I am setting up to rewrite subdomains as get parameters
So,
subdomain.example.com/blog/test
would actually point to:
example.com/index.php?website=subdomain&request=blog/test
I have setup the domain with an A record with a value of *, and I have setup the server to ALIAS *.example.com to example.com. All of that is working.
In my .htaccess I have
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} ^([^/\.]+).example.com(.*)$ [NC]
RewriteRule ^(.*)$ index.php?website=%1&request=%2 [L]
Here is a var_dump() of $_GET when i go to subdomain.example.com/blog/test
array(2) { ["website"]=> string(8) "subdomain" ["request"]=> string(0) "" }
the subdomain is coming in perfectly in the website parameter, but the rest of the request is not there in the request parameter. Any Ideas? I really appreciate the help. Thanks in advance.
By the way if I use
RewriteRule ^(.*)$ index.php?website=%1&request=$1 [L]
Then I get index.php in the request parameter. If that tells you something additional.
AMENDMENT
Per John’s suggestion I tried the following
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} ^([^/\.]+).wescms.com(.*) [NC]
RewriteRule ^(.*)$ index.php?website=%1&request=%{REQUEST_URI} [NC,L]
If you go to subdomain.example.com/blog/test the REQUEST_URI comes back with index.php
I did a var_dump() of the $_SERVER variable, and in the REQUEST_URI it shows /blog/test, but its not making it through the RewriteRule.
If I use THE_REQUEST in the rewrite rule rather than REQUEST_URI, I get back what I need plus some extra bits but I would appreciate understanding more about why REQUEST_URI is not working as in my last example. Thanks.
Your second
RewriteCondis matching against%{HTTP_HOST}, which only includes the hostname the of the request, not the “path” portion.The requested resource (basically, the part of the URL after the hostname) is available as the
%{REQUEST_URI}variable. In your situation, you could use the variable directly in your rule rather than trying to capture that data in aRewriteCond.