Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.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_Mod Rewrite - Fatal编程技术网

Apache 使用.htaccess将主域重定向到子文件夹,而不影响辅助域

Apache 使用.htaccess将主域重定向到子文件夹,而不影响辅助域,apache,.htaccess,redirect,mod-rewrite,Apache,.htaccess,Redirect,Mod Rewrite,我有两个域名: gyanplease.com/gyanplease主域(我在.htaccess的帮助下更改了文档根目录) mobiledevsolutions.comsecondary域 在文档根目录上,我创建了一个名为gyanplease的文件夹,并在.htaccess的帮助下,我将gyanplease.com重写到gyanplease文件夹中。这是重定向的代码: #disable https RewriteEngine on RewriteCond %{HTTPS} on Rewrite

我有两个域名:

  • gyanplease.com/gyanplease
    主域(我在
    .htaccess
    的帮助下更改了文档根目录)
  • mobiledevsolutions.com
    secondary域
在文档根目录上,我创建了一个名为
gyanplease
的文件夹,并在
.htaccess
的帮助下,我将
gyanplease.com
重写到
gyanplease
文件夹中。这是重定向的代码:

#disable https
RewriteEngine on
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} !gyanplease/
RewriteRule (.*) /gyanplease/$1 [L]

现在,当我在同一台服务器上托管另一个域时,即
mobiledevsolutions.com
,该域不工作,并出现404重定向错误。

您所能做的只是为该主机运行
/gyanplease/
重写,如下所示(替换最后两行):

这样,此规则只会影响gyanplease.com

您还可以将第4行更改为该行,因为未使用捕获:

RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
因此,所有这些都将构成您的新规则:

RewriteEngine on
# Disable HTTPS
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Rewrite gyanplease.com to /gyanplease/
RewriteCond %{HTTP_HOST} (?:^|\.)gyanplease.com$
RewriteCond %{REQUEST_URI} !^/gyanplease/
RewriteRule ^(.*)$ /gyanplease/$1 [L]
RewriteEngine on
# Disable HTTPS
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Rewrite gyanplease.com to /gyanplease/
RewriteCond %{HTTP_HOST} (?:^|\.)gyanplease.com$
RewriteCond %{REQUEST_URI} !^/gyanplease/
RewriteRule ^(.*)$ /gyanplease/$1 [L]