首页 文章

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

提问于
浏览
1

这似乎是一种罕见的情况,因为到目前为止我还没有找到它的线程 .

我有一个内置在子目录中的wordpress网站(例如example.com/subdir/是主页) .

我现在正在同一个域上构建一个新站点来取代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,并且没有骰子 .

1 回答

  • 0

    在其他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>
    

相关问题