Mod rewrite 使用带有Mod Rewrite的通配符子域?

Mod rewrite 使用带有Mod Rewrite的通配符子域?,mod-rewrite,subdomain,wildcard-subdomain,Mod Rewrite,Subdomain,Wildcard Subdomain,我有通配符子域,但我只是不知道mod_重写到需要写这个的程度。有谁能告诉我如何使它除了www之外的任何东西都不会进入主站点,而是进入/script/index.php以外的任何子域?username=$username $username变量应该来自哪里 假设主站点的URL为,并且您正在使用此外部目录上下文(即,不在.htaccess中,也不在指令中)。如果在.htaccess中,则删除前导/(例如,将其设置为main_site.php) 我认为这不会马上起作用,因为存在许多不明确的变量(用户名

我有通配符子域,但我只是不知道mod_重写到需要写这个的程度。有谁能告诉我如何使它除了www之外的任何东西都不会进入主站点,而是进入/script/index.php以外的任何子域?username=$username

$username变量应该来自哪里

假设主站点的URL为,并且您正在使用此外部目录上下文(即,不在.htaccess中,也不在指令中)。如果在.htaccess中,则删除前导/(例如,将其设置为main_site.php)

我认为这不会马上起作用,因为存在许多不明确的变量(用户名来自哪里?、如何处理请求的其余部分、将其作为参数传递?、这是htaccess还是main config?),但希望能让您了解:

#Turn on the rewrite engine
RewriteEngine On
#Check accessed domain, if it's either www.example.com or
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC,OR]
#example.com
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
#and the requested URL does not contain script you'll be accessing to avoid looping
RewriteCond %{REQUEST_URI} !main_site.php
#Then we tell that everything matching the above will go to main_site.php
RewriteRule ^ /main_site.php [L]
#If the request is not asking for main_site.php nor index.php
RewriteCond %{REQUEST_URI} !main_site.php
RewriteCond %{REQUEST_URI} !index.php
#We go to /script/index.php (username will be empty, becase we don't know 
#where to get it from)
RewriteRule ^ /script/index.php?username=$username [L]

你的意思是“有人能告诉我如何使www和nothing进入主站点吗…”用户名来自子域。如果它是nothing(即,just domain.com),该怎么办?