I transferred my website from olddomain.de to newdomain.de and wanted to redirect every page of the old website to the new website (eg olddomain.de/contact -> newdomain.de/contact). When I enter the main page of the old website in the browser, I am redirected correctly but all other pages are not redirected.
I tried a lot of different redirect options and currently this one is implemented (the first IfModule already existed):
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ http://www.newdomain.de/$1 [R=301,L]
</IfModule>
# END WordPress
Does anyone know how to correct the .htaccess file, so that all pages of the website are being redirected?
I managed to get all sites redirected by putting some code at the top of the IfModule like this
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^olddomain.de$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.de$
RewriteRule (.*)$ http://newdomain.de/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Since this is working fine now, I wanted to change the address in the google search console but it says that the 301 redirection is not working. Does anyone have any suggestions here?
since your old site is not serving a WordPress instance anymore try removing the first part of your .htaccess file (you don't need it and may be causing the issue.
So let it just like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ http://www.newdomain.de/$1 [R=301,L]
</IfModule>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.