【问题标题】:Multiple domains mapped to separate index pages with .htaccess使用 .htaccess 将多个域映射到单独的索引页
【发布时间】:2015-03-06 19:30:37
【问题描述】:

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

喜欢:

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 的回答,Panama Jack 的解释。谢谢! 概括原因是我的 html 文件的名称是 url 的一部分。 :)

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

【问题讨论】:

  • 如果您使用域名,它将执行外部重定向。所以你只需要重写file 本身或使用[P] 标志来代理。

标签: apache .htaccess


【解决方案1】:

应该是:

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]

【讨论】:

  • 太棒了!您是 .htaccess 大师! RewriteCond %{HTTP_HOST} ^(www\.){0,1}domain(.+)\.com$ [NC] RewriteRule ^/?$ %2.html [L]
猜你喜欢
  • 1970-01-01
  • 2018-02-20
  • 1970-01-01
  • 2018-09-29
  • 1970-01-01
  • 1970-01-01
  • 2020-08-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多