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
secondary域mobiledevsolutions.com
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]