.htaccess 多个加载域,一个htaccess文件
比如说,我的根域名是main.com,我有两个附加域:addon1.com和addon2.com 我的脚本已经准备好,我可以看到我的网站,如下所示:.htaccess 多个加载域,一个htaccess文件,.htaccess,addon-domain,.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
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)
但我得到了500的间隔误差。有什么建议吗
提前感谢。您的规则正在循环。php
/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
您需要包括“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]
谢谢你的回答。但是它试图加载main.com/addon1.com/show.php,show.php位于根文件夹(main.com/show.php)中。
# 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]