虽然不受欢迎,但可以使用 mod_rewrite 动态设置您的停放域子主机。
这是一个 .htaccess 示例,用于通过 mod_rewrite 使用动态格式进行多主机托管,该格式需要 parked-domain-name = sub-folder-name,并涵盖您网站上被重定向或忽略的其他托管域。
# tell mod_rewrite to activate and give base for relative paths
RewriteEngine on
RewriteBase /
# permanent redirect of unused parked domains so they do not try to resolve.
# only use this redirect if you want multiple names to point to another.
# otherwise, replace the rewrite rule with: RewriteRule . - [F,L]
RewriteCond %{HTTP_HOST} ^(www\.)?parked-domain1\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?parked-domain2\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?parked-domain3\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?parked-domain4\.com$ [NC]
RewriteRule ^(.*)$ http://main-site.com/$1 [L,R=301]
# if you have an active site in hosting root folder,
# then tell it not to look for a subfolder by skipping next rule
RewriteCond %{HTTP_HOST} ^(www\.)?main-site\.com [NC]
RewriteRule ^(.*)$ - [S=1]
# the domain-name = sub-folder automation
# thus parked-domain5.com in /parked-domain5/
RewriteCond %{HTTP_HOST} ([^.]+)\.com
RewriteCond %{REQUEST_URI} !^/%1
RewriteRule ^(.*)$ %1/$1 [L]
# if you're hosting wordpress sites, this is a tweaked variant of the WP code.
# add the rest of this example only if:
# 1. main-site.com is a WP site
# 2. you remove .htaccess in subfolders
# if (1.) true, yet keeping subfolder .htaccess, uncomment next 2 lines:
# RewriteCond %{HTTP_HOST} !^(www\.)?main-site\.com [NC]
# RewriteRule ^(.*)$ - [S=1]
#### BEGIN WordPress, improved
# if this request is for "/" or has already been rewritten to WP
RewriteCond $1 ^(index\.php)?$ [OR]
# or if request is for image, css, or js file
RewriteCond $1 \.(gif|jpg|jpeg|png|css|js|ico)$ [NC,OR]
# or if URL resolves to existing file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# or if URL resolves to existing directory
RewriteCond %{REQUEST_FILENAME} -d
# then skip the rewrite to WP
RewriteRule ^(.*)$ - [S=1]
# else rewrite the request to WP
RewriteRule . /index.php [L]
# END WordPress