使用 .htaccess 将多个域映射到单独的索引页面

Multiple domains mapped to separate index pages with .htaccess

我们有许多指向托管文件夹的域,我想根据域名为根目录提供不同的页面。

喜欢:

http://domainone.com --> serves up one.html as index page
http://domaintwo.com --> serves up two.html as index page

我想为每个域提供不同的页面,但我不想重定向它们。差不多,我想用 .htaccess 路由或映射到这些文件。

我知道了,但它会进行重定向并显示文件名。无论如何要映射它?

RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.){0,1}domain(.+)(\.com)$ [NC]
RewriteRule ^ %{ENV:PROTO}://domain%2\.com/%2.html [L]

答案:

anubhava 的回答,巴拿马杰克的解释。谢谢! 普遍原因是我的 html 文件名是 url 的一部分。 :)

RewriteCond %{HTTP_HOST} ^(www\.){0,1}domain(.+)\.com$ [NC]
RewriteRule ^/?$ %2.html [L]

应该是:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?domainone\.com$ [NC]
RewriteRule ^/?$ one.html [L]

RewriteCond %{HTTP_HOST} ^(www\.)?domaintwo\.com$ [NC]
RewriteRule ^/?$ two.html [L]