繁体   English   中英

htaccess从内置在子目录中的站点重定向

[英]htaccess redirect from site built in a subdirectory

这似乎是一种罕见的情况,因为到目前为止我还无法在其上找到线程。

我在子目录(即example.com/subdir/是主页)中建立了一个wordpress网站。

我现在在同一域上构建一个新站点来替换example.com/subdir/,它将位于example.com的根目录中。

我需要301将example.com/subdir/folder1/下的所有页面重定向到example.com/newfolder/下的一页

我没有很多htaccess经验,但是我希望以下htaccess文件可以工作(我将其放在example.com/subdir/目录中)。 但是,它仍然允许我访问example.com/subdir/folder1/及其下的所有页面,而无需重定向到example.com/newfolder/

我究竟做错了什么?

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdir/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdir/index.php [L]

RedirectMatch 301 ^/folder1(.*)$ http://example.com/newfolder/
</IfModule>

我还尝试了Redirect 301命令而不是RedirectMatch 301,并且没有骰子。

在其他WP规则之前有301条规则:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdir/

RewriteRule ^folder1(.*)$ http://example.com/newfolder/ [L,R=301]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdir/index.php [L]

</IfModule>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM