Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.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_Redirect_Https - Fatal编程技术网

Php htaccess重定向子目录及其内容

Php htaccess重定向子目录及其内容,php,apache,.htaccess,redirect,https,Php,Apache,.htaccess,Redirect,Https,以下是我的初始重定向规则: RewriteCond %{HTTP_HOST} !^sub1\.myinitialdomain\.com$ [NC] RewriteCond %{HTTP_HOST} !^sub2\.myinitialdomain\.com$ [NC] RewriteRule ^(.*)$ https://www.mydomain.com/$1 [L,R=301] 这基本上将整个网站重定向到新域,除了sub1和sub2之外 但是,我在/wordpress上安装了一个wordpre

以下是我的初始重定向规则:

RewriteCond %{HTTP_HOST} !^sub1\.myinitialdomain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^sub2\.myinitialdomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [L,R=301]
这基本上将整个网站重定向到新域,除了
sub1
sub2
之外

但是,我在
/wordpress
上安装了一个wordpress,我有以下规则来重定向所有文章:

RewriteCond %{REQUEST_URI} wordpress 
RewriteRule ^(.*)$ https://www.mydomain.com/blog/$1 [R,L]

但是,即使文章被正确重定向,主
/wordpress
目录也没有被正确重定向。它被重定向到
https://www.mydomain.com/blog/wordpress


我需要能够组合规则,但要确保
/worpress
和其中的任何文章都被重定向到
https://www.mydomain.com/blog/

您可以使用此规则重定向
/wordpress/.htaccess
文件中的所有内容:

RewriteEngine On
RewriteRule ^(.*)$ https://www.mydomain.com/blog/$1 [NC,L,NE,R=302]

RewriteCond %{HTTP_HOST} !^(sub1|sub2)\.myinitialdomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [L,NE,R=302]

确保这是
/wordpress/.htaccess
文件中的第一条规则。

它应该重定向到什么?您所拥有的规则似乎重定向到您所说的要重定向到的位置。
https://www.mydomain.com/blog/
-我编辑了我的问题,将初始规则也包括在内。这是一个永久重定向。那么,我是否应该将
302
更改为
301
?首先确保它能根据您的需要工作。验证后,您可以将其更改为
301
。第二组条件。。。那会在根htaccess文件中,对吗?