Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 是否需要帮助修改此htaccess代码?_Apache_.htaccess_Redirect_Rewrite - Fatal编程技术网

Apache 是否需要帮助修改此htaccess代码?

Apache 是否需要帮助修改此htaccess代码?,apache,.htaccess,redirect,rewrite,Apache,.htaccess,Redirect,Rewrite,不久前,在很多帮助下,我整理了这些代码,并为我的插件域添加了排除。这些是独立的域,它们自己的文件夹位于公共html中。但服务器将它们视为子域。如果没有排除,所有URL都将重定向到主域。所以一切都很好。但现在我进入了域名行业,需要托管许多域名。每次我添加一个域时,我都必须进入主站点htaccess并将其添加到代码中以进行排除。这是一种痛苦。是否需要重写此代码,使其自动执行,这样我就不必输入每个新域 代码目前去掉index.html/php并重写到文件夹。当不存在时强制www 所以root(/)是m

不久前,在很多帮助下,我整理了这些代码,并为我的插件域添加了排除。这些是独立的域,它们自己的文件夹位于公共html中。但服务器将它们视为子域。如果没有排除,所有URL都将重定向到主域。所以一切都很好。但现在我进入了域名行业,需要托管许多域名。每次我添加一个域时,我都必须进入主站点htaccess并将其添加到代码中以进行排除。这是一种痛苦。是否需要重写此代码,使其自动执行,这样我就不必输入每个新域

代码目前去掉index.html/php并重写到文件夹。当不存在时强制www

所以root(/)是main域。And/addondomain是加载项域所在的位置

谢谢你的帮助

# 301 permanent redirect index.html(htm) to folder with exclusion for addon domains
RewriteCond %{HTTP_HOST} !(addondomain\.com)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html?$ http://www.maindomain.com/$1 [R=301,L]

# 301 permanent redirect non-www (non-canonical) to www with exclusion for addon domains
RewriteCond %{HTTP_HOST} !(addondomain\.com)
RewriteCond %{HTTP_HOST} !^(www\.maindomain\.com)?$
RewriteRule (.*) http://www.maindomain.com/$1 [R=301,L]

如果我理解正确,为什么不做相反的事情呢

确保这些规则仅适用于
(www.maindomain.com
。如下所示:

# Place this rule first.
# Instead of excluding, add *www* only to main domain when necessary:
RewriteCond %{HTTP_HOST} ^maindomain\.com  [NC] 
RewriteRule ^(.*) http://www.maindomain.com/$1 [R=301,L]

# Instead of excluding, use the rule only for main domain:
RewriteCond %{HTTP_HOST} ^www\.maindomain\.com     [NC] 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html?$  /$1 [R=301,L]
此规则集应放在主域中根目录下的.htaccess文件中

我没有测试或修改规则,也不能说它们是否按预期工作,只是在每个规则中替换了1个条件