First, I am sorry if there are similar threads, but I cannot figure out what is the right approach for the following problem:
I cannot figure out, how to properly change my .htaccess files, so that the following conditions will work:
I have 2 independent WordPress instances under one domain. (Lets say: example.com)
Current behaviour when i access example.com:
Desired behaviour, when i access example.com:
My first approach was to add the following line in the /old/.htaccess:
Redirect 301 / https://example.com/new/
But then, it redirected example.com to: example.com/new/old/ which resulted in a 404. Since the .htaccess files look kind of identical in /old/ and /new/ I cannot figure out, where exactly is defined, that example.com/ is redirecting to /old/ by default.
Here are the .htaccess contents of each instance and root folder:
# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/
RewriteRule .* - [CO=wordpress_test_cookie:WP+Cookie+check:%{HTTP_HOST}:1440:/]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /old/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /old/index.php [L]
</IfModule>
# END WordPress
#BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /new/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /new/index.php [L]
</IfModule>
# END WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Header always set Content-Security-Policy "upgrade-insecure-requests;"
</IfModule>
Any help is highly appreciated.
Thank you.
You need to use a RewriteRule
in your old/. htaccess
instead of using Redirect
. A RewriteRule can map the request from your old
directory to the new
directory without a change in URL.
RewriteEngine On
RewriteCond %{REQUEST_URI} !/new [NC]
RewriteRule ^(.*)$ /new/$1 [L]
This should go in htaccess in your /root
directory and remember to put this at the top or before other rewriting directives.
Also change "WordPress home URL" and "Site address" by going to settings->general
in your WordPress dashboard.
You can use https://example.com
as the WordPress home URL and https://example.com/new
as your WordPress site address.
Let me know how it works for you.