正在重定向到未完全显示URL的子目录(.htaccess)



我正在使用wordpress,并试图将网站上的页面定向到另一个子目录,但它在加载时删除了一个目录。

示例:

要重定向的URL:example.com/blog/directory/

目标URL:example.com/blog/new-directory/more-directory/

最终URL:example.com/new-directory/more-directory/

它删除了"博客"目录,然后给我一个404。如果能在这方面得到一些帮助就太好了,

使用.htaccess更新:

<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
RedirectMatch 301 /blog/files/(.*) /files/$1
RedirectMatch 301 /blog/directory/(.*) /blog/new-directory/more-directory/$1
</IfModule>

如果您可以访问example.com/blog/directory/的页面html文件,只需在文件中插入以下代码

<META http-equiv="refresh" content="0;URL=example.com/blog/new-directory/more-directory/">

不要将mod_alias规则与mod_rewrite混合,并且在WP之前有301规则。

这应该在您的/blog/.htaccess:中

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
Options +FollowSymLinks
RewriteRule ^files/(.*)$ /files/$1 [L,R=301,NC]
RewriteRule ^directory/(.*)$ new-directory/more-directory/$1 [L,R=301,NC]
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

最新更新