Rewrite rule for dynamic subdomain redirecting each file with subdomain arguments
I want to redirect all the calls to files in a subdomain with an extra varia开发者_C百科ble. like if a user access www.domain.com/news.php
and in the subdomain he accesses the same page then it should add an extra argument to the url like xyz.domain.com/news.php
should be re written like it calls the file news.php?subdomain=xyz
. Also i have other rules for just simple domain.
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC]
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$
RewriteRule ^$ /index.php?subdomain=%1 [L]
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC,L]
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ http://www.domain.com%{REQUEST_URI}?subdomain=%1 [L]
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^(.*)$ http://www.domain.com%{REQUEST_URI}?%{QUERY_STRING}&subdomain=%1 [L]
The solution pointed to by adaptr at: https://serverfault.com/a/409171/128746 - would solve this problem very well.
精彩评论