[英]htaccess Redirect subdirectory and its contents
Here is my initial redirect rule: 这是我最初的重定向规则:
RewriteCond %{HTTP_HOST} !^sub1\.myinitialdomain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^sub2\.myinitialdomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [L,R=301]
That basically redirects the entire website, except for sub1
and sub2
to the new domain. 这基本上将整个网站重定向,除了sub1
和sub2
之外,都将其重定向到新域。
However, I've got a wordpress install at /wordpress
and I've got the following rule in place to redirect all of the articles: 但是,我已经在/wordpress
wordpress上安装了/wordpress
并具有以下规则来重定向所有文章:
RewriteCond %{REQUEST_URI} wordpress
RewriteRule ^(.*)$ https://www.mydomain.com/blog/$1 [R,L]
But even though the articles are being redirected correctly, the main /wordpress
directory is not being redirected correctly. 但是,即使文章被正确地重定向,主/wordpress
目录也没有被正确地重定向。 It's being redirected to https://www.mydomain.com/blog/wordpress
它被重定向到https://www.mydomain.com/blog/wordpress
I need to be able to combine the rules, but make sure that /worpress
and any articles within that are being redirected to https://www.mydomain.com/blog/
我需要能够合并规则,但是请确保/worpress
和其中的任何文章都被重定向到https://www.mydomain.com/blog/
You can use this rule to redirect everything from within /wordpress/.htaccess
file: 您可以使用此规则来重定向/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]
Make sure this is first rule in /wordpress/.htaccess
file. 确保这是/wordpress/.htaccess
文件中的第一条规则。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.