0

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

我的脚本已经准备好了,我可以看到这样的网站:

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

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

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

我将一个 htaccess 文件写入根文件夹(main.com/.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 间隔错误。有什么建议吗?

提前致谢。

4

2 回答 2

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
于 2012-01-11T20:47:25.747 回答
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]
于 2017-07-27T07:16:38.460 回答