简体   繁体   English

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

[英]htaccess redirect from site built in a subdirectory

this seems like kind of a rare situation, as i haven't been able to find a thread on it so far. 这似乎是一种罕见的情况,因为到目前为止我还无法在其上找到线程。

i have a wordpress site built in a subdirectory (ie example.com/subdir/ is the homepage). 我在子目录(即example.com/subdir/是主页)中建立了一个wordpress网站。

i am now building a new site on the same domain to replace example.com/subdir/ and it will be located at example.com, in the root directory. 我现在在同一域上构建一个新站点来替换example.com/subdir/,它将位于example.com的根目录中。

i need to 301 redirect all pages under example.com/subdir/folder1/ to one page at example.com/newfolder/ 我需要301将example.com/subdir/folder1/下的所有页面重定向到example.com/newfolder/下的一页

i don't have a lot of htaccess experience, but i expected the following htaccess file to work (i placed it in the example.com/subdir/ directory). 我没有很多htaccess经验,但是我希望以下htaccess文件可以工作(我将其放在example.com/subdir/目录中)。 however, it is still letting me visit example.com/subdir/folder1/ and all pages underneath it without redirecting me to example.com/newfolder/ 但是,它仍然允许我访问example.com/subdir/folder1/及其下的所有页面,而无需重定向到example.com/newfolder/

what am i doing wrong? 我究竟做错了什么?

<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>

i also tried it with the Redirect 301 command instead of RedirectMatch 301, and no dice. 我还尝试了Redirect 301命令而不是RedirectMatch 301,并且没有骰子。

Have 301 rules before other WP rules: 在其他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