I have a wordpress installed in a subfolder called blog/ I have two htaccess files, one in the root directory, one in blog folder, generated by wordpress.
The first htaccess in root directory:
# BEGIN
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(blog/.*)$
<IfModule mod_rewrite.c>
Redirect 301 "/old_page" "http://example.com/new-page"
...
<IfModule>
# END
The second htaccess in blog folder:
# 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
My issue is when I navigate to http://example.com/blog/, I'm redirected to a link like that: http://example.com/index.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlblog/
CodePudding user response:
I have checked your Htaccess code used for the subfolder URL, it will work fine and I have modified the root directory Htaccess code for redirection.
Please try to below code for this.
RewriteEngine on
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /blog/$1 [L]
SubFolder Htaccess code
<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>
CodePudding user response:
You can use the below code for the old URL to new URL:
<IfModule mod_rewrite.c>
RewriteEngine On
RedirectMatch 301 /old-page/ /new-page/
<IfModule>