Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.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
Php .htaccess在不影响子域的情况下重定向_Php_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Php .htaccess在不影响子域的情况下重定向

Php .htaccess在不影响子域的情况下重定向,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,我在home/user/public_html中有我们的主网站,在home/user/sub中有一个子域 它们都是Joomla网站 在home/user/public_html中,我有下面的.htaccess文件,我使用该文件使我们主网站的每个页面访问都使用https和www-使用的代码是: RewriteEngine On RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} !^www\. RewriteRule (.*) https://ww

我在home/user/public_html中有我们的主网站,在home/user/sub中有一个子域

它们都是Joomla网站

在home/user/public_html中,我有下面的.htaccess文件,我使用该文件使我们主网站的每个页面访问都使用https和www-使用的代码是:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.%{HTTP_HOST}/$1 [R=301,L]
上面的.htaccess文件正在将所有子域访问重定向到https://www.sub.example.com.au-如何阻止它这样做,同时将所有子域访问加载到https://sub.example.com.au

我认为.htaccess文件只会影响其中的目录,但它似乎会影响子域,即使它不在public_html文件夹中

谢谢你的建议。谢谢


注意:由于我没有足够的声誉,我不得不在上面的一些链接中添加空格。

简单的答案是不要使用正则表达式匹配主机名

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} example.com.au
RewriteRule (.*) https://www.example.com.au/$1 [R=301,L]

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} www.example.com.au
RewriteRule (.*) https://www.example.com.au/$1 [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} example.com.au
RewriteRule (.*) https://www.example.com.au/$1 [R=301,L]
另一个选项是在Apache配置中对虚拟主机进行udpating:

<VirtualHost *:80>
    ServerName example.com.au:80
    ServerAlias www.example.com.au:80
    RedirectPermanent / https://www.example.com.au/
</VirtualHost>

<VirtualHost *:443>
    ServerName example.com.au:443
    RedirectPermanent / https://www.example.com.au/
</VirtualHost>

<VirtualHost *:443>
    ServerName www.example.com.au:443
    # server config goes here
</VirtualHost>

ServerName example.com.au:80
ServerAlias www.example.com.au:80
重定向永久/https://www.example.com.au/
ServerName example.com.au:443
重定向永久/https://www.example.com.au/
服务器名www.example.com.au:443
#这里是服务器配置

但是,可能的解释是,
.htaccess
文件已在子域目录中复制或符号链接到子域目录。

您确定您的子域将
/home/user/sub
用作文档根目录吗
.htaccess
文件只影响它们所在的目录和子目录。我假设问题是,您在子域根目录中有一个类似的
.htaccess
文件,apache没有为子域正确设置,正在加载主根目录,或者这些规则存在于apache配置中,因此它们会影响所有站点。谢谢。我肯定它们所在的目录,是的,子目录也有自己的.htaccess(默认的Joomla目录)。关于apache没有正确设置域,您可能是正确的。我将尝试删除并读取它。谢谢miken32。我尝试了您建议的.htaccess更改(在public_html.htaccess文件中,然后是sub-one,但没有任何区别)。虚拟主机ApacheConfig对我来说太过分了。我对public_html.htaccess文件进行了更改,以测试并得出结论,就是该文件导致了重定向,即使它位于指向子。。。。我已经把网站移到了另一个网络服务器上,它马上就按预期工作了…@AdamGatt:请不要接受那些对你不起作用的答案。