我有一个完整的网站,如:
http://www.example.com (uses index.php) http://www.example.com/scriptA.php http://www.example.com/scriptB.php
我现在想要build立子网站的可能性如下:
http://alpha.example.com http://alpha.example.com/scriptA.php http://alpha.example.com/scriptB.php
从https://stackoverflow.com/questions/2844004/subdomain-url-rewriting-and-web-apps/2844033#2844033 ,我明白,我必须这样做:
RewriteCond %{HTTP_HOST} ^([^./]+)\.example\.com$ RewriteCond %1 !=www RewriteRule ^ index.php?domain=%1
但是其他脚本如scriptA和scriptB呢? 我如何告诉httpd.conf正确处理这些?
我怎么能告诉httpd.conf处理“forwardslash”之后的所有内容 ,就像在主站点上一样,但是传递一个参数标志
&domain=alpha
EDIT1
... I have lots of these subdomains being used, but I placed them _before_ the main 'www' one. ... <VirtualHost IPADDRESS:80> ServerAlias test4.example.com ServerAdmin [email protected] DocumentRoot /home/test4/public_html ServerName test4.example.com UseCanonicalName On </VirtualHost> <VirtualHost IPADDRESS:80> ServerAlias *.example.com ServerAdmin [email protected] DocumentRoot /var/www/html/beta ServerName example.com UseCanonicalName On <IfModule mod_geoip.c> GeoIPEnable On GeoIPDBFile /opt/GeoLiteCity.dat IndexCache </IfModule> <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC,L] RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC] RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$ [NC] RewriteCond %{QUERY_STRING} ^$ RewriteRule ^(.*)$ http://www.example.com%{REQUEST_URI}?domain=%1 [L] RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC] RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$ [NC] RewriteCond %{QUERY_STRING} !^$ RewriteRule ^(.*)$ http://www.example.com%{REQUEST_URI}?%{QUERY_STRING}&domain=%1 [L]
如果你希望所有这些URL最终都在同样的3个脚本上 – 就像我从你的页面中揣测的那样 – 完整的数据 – 那你就不需要这些东西了。
只需重写一个相对的 URI:
RewriteCond %{HTTP_HOST} ^([^./]+)\.example\.com$ RewriteRule ^(.*\.php)$ $1?domain=%1 [QSA]
这将适用于任何url。
我怀疑你是无缘无故的让事情变得可怕 – 虚幻和redirect的明智组合将解决大多数问题,而不需要复杂的重写。