多个插件域,一个htaccess文件

时间:2012-01-11 20:40:33

标签: .htaccess addon-domain

可以说,我的根域名是 main.com ,我有两个插件域: addon1.com addon2.com

我的脚本已经准备就绪,我可以看到我的网站:

    www.main.com/show.php?domain=addon1.com 

但是,我想要的是通过他们的域名显示网站。我的意思是当我打开addon1.com时,我希望看到 show.php?domain = addon1.com 的输出。这两个域也作为插件添加,其目录为:

    main.com/addon1.com/
    main.com/addon2.com/

我在根文件夹(main.com/.htaccess)中写了一个htaccess文件

    Options +FollowSymLinks
    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^www\.addon1\.com$ [NC]
    RewriteRule ^(.*)$ /show.php?domain=addon1.com&$1

    RewriteCond %{HTTP_HOST} ^www\.addon2\.com$ [NC]
    RewriteRule ^(.*)$ /show.php?domain=addon2.com&$1

但我得到500区间错误。有什么建议吗?

提前致谢。

2 个答案:

答案 0 :(得分:0)

您的规则正在循环播放。 /show.php将通过重写引擎返回并无限循环。您需要添加条件,以便它们不循环:

RewriteCond %{HTTP_HOST} ^www\.addon1\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/show.php
RewriteRule ^(.*)$ /show.php?domain=addon1.com&$1

RewriteCond %{HTTP_HOST} ^www\.addon2\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/show.php
RewriteRule ^(.*)$ /show.php?domain=addon2.com&$1

答案 1 :(得分:0)

您需要包含" RewriteBase "帮忙。

# tell mod_rewrite to activate and give base for relative paths
  Options +FollowSymLinks
  RewriteEngine on
  RewriteBase   /

# for the active site in hosting root folder,
# tell it not to look for a subfolder by skipping next rule
  RewriteCond %{HTTP_HOST}   ^(www\.)?main\.com [NC]
  RewriteRule ^(.*)$         - [S=1]

# the domain-name = sub-folder automation
# thus addon-domain.com in /addon-domain(\.com)?/
  RewriteCond %{HTTP_HOST}   ([^.]+)\.com
  RewriteCond %{REQUEST_URI} !^/%1
  RewriteRule ^(.*)$         %1/$1 [L]

# to answer your question swap the above 
# domain-name = sub-folder automation for this rule
  RewriteCond %{HTTP_HOST}   ([^.]+)\.com$ [NC]
  RewriteCond %{REQUEST_URI} !^/show.php
  RewriteRule ^(.*)$         /show.php?domain=%1&$1 [L]
# although, the above line may require this instead
  RewriteRule .              main.com/show.php?domain=%1&$1 [L]