两个域,一个共享服务器,.htaccess文件

时间:2012-01-11 21:20:00

标签: .htaccess

我查看了很多其他“两个域名,一个服务器”的问题,并没有看到我正在寻找的确切内容......

我有两个域名,www.example1.com和www.example2.com。他们在apache的共享托管环境中。我想要:

A)example1.com只加载普通的index.html文件(在wordpress安装上) B)example2.com转到子文件夹/ forums /

所以,换句话说,我希望example1.com成为我的主要(正常和快乐)域,而example2.com只需要加载/ forums /目录。

我想我可能只需要一个重写规则,例如example2.com去/ forums /?

我希望这是有道理的:)。非常感谢您提供的任何帮助。

2 个答案:

答案 0 :(得分:0)

尝试将以下内容添加到域中根文件夹中的htaccess文件中。

RewriteEngine on 
RewriteBase / 

#if on www.example1.com domain
RewriteCond %{HTTP_HOST} ^www\.example1\.com$ [NC]
#and not an existing file of directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#then send all requests to index.php
RewriteRule ^ index.php [L]


#if on www.example2.com domain
RewriteCond %{HTTP_HOST} ^www\.example2\.com$ [NC]
#if not already in forums directory
RewriteCond %{REQUEST_URI} !/forums/ [NC]
#rewrite requests to forums directory
RewriteRule (.*) forums/$1 [L]

答案 1 :(得分:0)

也许对某人有用。扫描并尝试以下各种方法似乎完美。我正在使用Apache服务器。在我的htaccess文件中,在IfModule之后我添加了<If>条件并且它工作正常。

<IfModule>
.
.
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>
<If "%{HTTP_HOST} == 'www.xyzs.co.uk'">

    Redirect    permanent   /xyz1   /yyy1
    Redirect    permanent   /xyz2   /yyy2
    Redirect    permanent   /xyz3   /yyy3
    Redirect    permanent   /xyz4   /yyy4
<If>

更多阅读:http://httpd.apache.org/docs/2.4/expr.html

相关问题