I have a React app on https://example.com/
and a WordPress blog inside as a sub directory: https://example.com/blog/
The issue:
While browsing https://example.com/blog
, I want it to get redirected (301) at https://example.com/blog/
But currently it is showing Error 404 because it is treating https://example.com/blog
as a react page.
This is my root .htaccess
:
# Disable directory indexes and MultiViews
Options -Indexes -MultiViews
# Prevent mod_dir appending a slash to directory requests
DirectorySlash Off
RewriteEngine On
# Prevent any further processing if the URL already ends with a file extension
RewriteRule \.\w{2,4}$ - [L]
# Redirect any requests to remove a trailing slash
RewriteRule (.*)/$ /$1 [R=301,L]
# Rewrite /foo to /foo.html if it exists
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule (.*) $1.html [L]
# Otherwise, rewrite /foo to /foo/index.html if it exists
RewriteCond %{DOCUMENT_ROOT}/$1/index.html -f
RewriteRule (.*) $1/index.html [L]
and here is my WordPress .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]
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteCond %{REQUEST_URI} !^/wp-json
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
</IfModule>
What could I do to redirect https://example.com/blog
to https://example.com/blog/
? It should be 301 redirection.
I have tried adding rules to .htaccess
to both of the instances. But neither is working.