Htaccess issue with wordpress



我在一个名为blog/的子文件夹中安装了一个wordpress我有两个htaccess文件,一个在根目录,一个在blog文件夹,由wordpress生成。

根目录下的第一个htaccess:

# BEGIN
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(blog/.*)$
<IfModule mod_rewrite.c>
Redirect 301 "/old_page" "http://example.com/new-page"
...
<IfModule>
# END

blog文件夹中的第二个htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /blog/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
<IfModule>
# END WordPress

我的问题是,当我导航到http://example.com/blog/,我重定向到这样的链接:http://example.com/index.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlblog/

我已经检查了用于子文件夹URL的Htaccess代码,它将正常工作,我已经修改了重定向的根目录Htaccess代码。

请尝试下面的代码。

RewriteEngine on
RewriteCond %{HTTP_HOST} example.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /blog/$1 [L] 

子文件夹Htaccess代码

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /blog/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

您可以使用以下代码将旧URL转换为新URL:

<IfModule mod_rewrite.c>         
RewriteEngine On     
RedirectMatch 301 /old-page/ /new-page/
<IfModule>

最新更新